我有一个关于根据出生日期查找生日的问题,遗憾的是我在这个网站上没有找到这个问题的答案。
我希望为距离生日还有 X 天的每个日期设置一个数字。除了我很难使用他们的 DOB 和 datediff 。
我想要的是:
John: 0 --Today his birthday
Eric:0
Ben:1 -- In this week
Jerry:1
Jules: 2 -- In this month
Tom: 3 -- all other dates
Run Code Online (Sandbox Code Playgroud)
我尝试过使用DATEDIFFwith 格式,但问题是你不能使用DATEDIFF.
我尝试不使用,这返回了他们的出生日期。
这是我尝试过的代码:
SELECT *
FROM
(SELECT
[id],
[fullname] = CONCAT(E.[name],
(CASE
WHEN LEN(E.[preposition]) > 0
THEN ' ' + E.[preposition]
END),
', ', E.[givenname]),
[relationnumber],
[day] = (CASE
WHEN DATEDIFF(day, [birthday], '2021-09-09') < 1
THEN 0
WHEN DATEDIFF(day, [birthday], '2021-09-09') < …Run Code Online (Sandbox Code Playgroud) 我目前正在跟踪人们访问我们网站的时间.
每个用户都有为他们设定的时间量,无论是00:10:00(10分钟)还是100:00:00(100小时).
当我使用这行代码时出现问题:
<cfset seconds_left = datediff("s",variables.time_used,form.site_time)>
Run Code Online (Sandbox Code Playgroud)
如果其中一个变量超过24小时(24:00:00),则会抛出错误:
40:00:00是无效的日期或时间字符串.
关于如何解决这个问题的任何建议都会很棒,谢谢!
我想DATEDIFF在MySQL查询中使用这样的函数:
SELECT `ItemType`,
`DateOpen` AS StartDate,
IFNULL (`DateClosed`, CURDATE()) AS EndDate,
DATEDIFF(`EndDate`, `StartDate`) AS ItemLife
FROM `Items`
WHERE `ProjectID`=11
ORDER BY `ItemType` ASC
Run Code Online (Sandbox Code Playgroud)
由于该DATEDIFF部分,上述查询失败.我尝试使用和不使用后退标记的列名称没有区别.我的语法错了还是我违反了一些SQL语言规则?
取DATEDIFF一部分出来,使流畅运行查询.
希望有人能提供帮助.
谢谢
我需要计算两个日期之间的月份差异.
start = new Date(112, 4, 30) // Wed May 30 00:00:00 CEST 2012
end = new Date(111, 9, 11) // Tue Oct 11 00:00:00 CEST 2011
assert 8 == monthsBetween(start, end)
Run Code Online (Sandbox Code Playgroud)
使用Joda-Time,通过以下方式实现这一目标非常容易:
months = Months.monthsBetween(start, end).getMonths()
Run Code Online (Sandbox Code Playgroud)
如何在不使用其他库的情况下以Groovy方式实现此目的?
可能重复:
一小时差异,但仅限于某些日期
为什么:
strtotime('2012-11-01 00:00:00') - strtotime('2012-10-01 00:00:00')
Run Code Online (Sandbox Code Playgroud)
正在回归:
2674800
Run Code Online (Sandbox Code Playgroud)
当正确的值是:
2678400
Run Code Online (Sandbox Code Playgroud)
失踪了一个小时.
我在SQL Server 2008中进行DATEDIFF()调用,作为存储过程的一部分,它可能返回小至3秒或更短的值.我希望格式为MM:SS(即3秒时00:03).我最初在几分钟内使用了这个电话:
DATEDIFF(mi, SELECT MAX(startDate) FROM myTable , SELECT MAX(EndDate) FROM myTable)
但是,这会向下舍入到最近的分钟,从而消除秒值.如何使用DATEDIFF实现上面指定的格式?
我得到了这样的日期之间的时差:
$time1 = "2013-02-25 12:00:00";
$time2 = "2013-01-01 12:00:00";
$tdiff = strtotime($time1) - strtotime($time2);
Run Code Online (Sandbox Code Playgroud)
我想要提取日,小时和分钟$tdiff.输出应该像:35 days 6 hours 14 minutes
我真的搜索并尝试自己做点什么.但我无法获得真正的价值.
----编辑----我可以找到日期差异.我想从计算时间中提取天数,小时数,分钟数......
----编辑2 ----这是我完整的mysql代码
select (
select avg(UNIX_TIMESTAMP(tarih)) from table1
where action in (6) and who = '".$user."' and dates between '".$date1."' and '".$date."'
) - (
select avg(UNIX_TIMESTAMP(tarih_saat)) from table2
where action in (6) and active = 1 and dates between '".$date1."' and '".$date2."
)
Run Code Online (Sandbox Code Playgroud)
此查询返回真实的时间值.此查询对我来说正常.结果如下:215922.结果类型为UNIX_TIMESTAPM.所以我想知道这个时间戳中有多少天,几小时和几分钟.
你可以帮我吗,我使用下面的sql视图(然后我在水晶报告中使用).我需要有日期差异(以分钟为单位),但现在我需要排除周末.请帮忙 :)
SELECT intwc AS wc,
Datediff(n, start_date, end_date) AS time,
mh_start_date AS date,
'Repair' AS type
FROM dbo.xxxxxxx
Run Code Online (Sandbox Code Playgroud) 我有一个问题,计算月份与sql server查询2日期的差异
我试过用 DATEDIFF(MONTH, SD, ED)
这个例如
SD = '2013-12-10 00:00:00.000'
ED = '2014-12-09 00:00:00.000'
SELECT DATEDIFF(MONTH, SD, ED)
--result : 12 //this correct result
SD = '2013-12-10 00:00:00.000'
ED = '2014-12-10 00:00:00.000'
SELECT DATEDIFF(MONTH, SD, ED)
--result : 12 //this incorrect result, the result that i want is 13
SD = '2013-12-10 00:00:00.000'
ED = '2014-12-15 00:00:00.000'
SELECT DATEDIFF(MONTH, SD, ED)
--result : 12 //this incorrect result, the result that i want is 13
SD = '2013-12-01 00:00:00.000'
ED …Run Code Online (Sandbox Code Playgroud) 好的,所以这是一个看似显而易见的问题,但我只是没有完全关注......
我在一堆日期上运行了以下代码:
SELECT
DATEDIFF(DAY, Start, [End]) AS DIFD,
DATEDIFF(WEEK, Start, [End]) AS DIFW,
DATEDIFF(Month, Start, [End]) AS DIFM,
DATEDIFF(Year, Start, [End]) AS DIFY
FROM
Datetest
Run Code Online (Sandbox Code Playgroud)
这是我看到的结果:
Start End Description DIFD DIFW DIFM DIFY
2010-03-25 2011-03-25 Normal Year 365 52 12 1
2011-03-25 2012-03-25 Leap Year 366 53 12 1
2010-03-24 2011-03-25 Add 1 day 366 52 12 1
2010-03-24 2011-03-26 Add 2 day 367 52 12 1
2010-03-24 2011-03-27 3 days 368 53 12 1
2010-03-24 2011-03-28 4 days 369 …Run Code Online (Sandbox Code Playgroud)