我有一个日期时间,其字符串格式为Y-m-d H:i:s
,如下所示:
$dateTime = '2018-07-06 18:53:21';
我想将其转换为dmy格式,如下所示:
$convertedDateTime = $this->convertDateTime($dateTime);
echo $convertedDateTime;
我在echo
上方期望得到的结果是 060718 ,我该如何实现?
答案 0 :(得分:3)
您可以像这样使用between...and
:
ALTER PROCEDURE [Servicing].[ManualAdjustments]
@dateFrom date,
@dateTo date
AS
BEGIN
With CTEMonths AS
(
SELECT Id, Name
FROM (VALUES
(1, 'January'),
(2, 'February'),
(3, 'March'),
(4, 'April'),
(5, 'May'),
(6, 'June'),
(7, 'July'),
(8, 'August'),
(9, 'September'),
(10, 'October'),
(11, 'November'),
(12, 'December')
) v(Id, Name)
)
SELECT *
FROM MyDatabase.dbo.MyTable
JOIN CTEMonths c ON RefMonth = c.Name
WHERE RefYear BETWEEN YEAR(@dateFrom) AND YEAR(@dateTo)
AND c.Id BETWEEN MONTH(@dateFrom) AND MONTH(@dateTo)
END
答案 1 :(得分:1)
main
答案 2 :(得分:1)
有两种使用方法:
date
-https://secure.php.net/manual/en/function.date.php
用法示例:
$myDate = '2018-07-06 09:49:00';
$myDate = date('d-m-y', strtotime($myDate));
但是您经常会想使用DateTime https://secure.php.net/manual/en/class.datetime.php:
$myDate = DateTime::createFromFormat('Y-m-d H:i:s', '2018-07-06 09:49:00');
$$newDate = $myDate->format('d-m-Y');