datediff

Twig date difference

丶灬走出姿态 提交于 2019-12-17 18:51:12
问题 I've got an entity with a starting date and an ending date. Is it possible to get the difference in time between them by using twig? 回答1: Since PHP 5.3 There is another option without to write an extension. This example show how to calc the plural day/days {# endDate and startDate are strings or DateTime objects #} {% set difference = date(endDate).diff(date(startDate)) %} {% set leftDays = difference.days %} {% if leftDays == 1 %} 1 day {% else %} {{ leftDays }} days {% endif %} Explanation:

DATEDIFF function in Oracle

守給你的承諾、 提交于 2019-12-17 16:37:10
问题 I need to use Oracle but DATEDIFF function doesn't work in Oracle DB. How to write the following code in Oracle? I saw some examples using INTERVAL or TRUNC. SELECT DATEDIFF ('2000-01-01','2000-01-02') AS DateDiff; 回答1: In Oracle, you can simply subtract two dates and get the difference in days . Also note that unlike SQL Server or MySQL, in Oracle you cannot perform a select statement without a from clause. One way around this is to use the builtin dummy table, dual : SELECT TO_DATE('2000-01

How to convert number of minutes to hh:mm format in TSQL?

三世轮回 提交于 2019-12-17 16:31:49
问题 I have a select query that has DURATION column to calculate number of Minutes . I want to convert those minutes to hh:mm format. Duration has values like 60, 120,150 For example: 60 becomes 01:00 hours 120 becomes 02:00 hours 150 becomes 02:30 hours Also, this is how I retrieve DURATION ( Minutes ) DATEDIFF(minute, FirstDate,LastDate) as 'Duration (Minutes)' 回答1: You can convert the duration to a date and then format it: DECLARE @FirstDate datetime, @LastDate datetime SELECT @FirstDate =

SQL Datediff - find datediff between rows

好久不见. 提交于 2019-12-17 15:44:54
问题 I would like to query a database using sql to show the difference in time between id 1,2,3 and so on. basically it will compare the row below it for all records. any help would be appreciated. IDCODE DATE TIME DIFFERENCE (MINS) 1 02/03/2011 08:00 0 2 02/03/2011 08:10 10 3 02/03/2011 08:23 13 4 02/03/2011 08:25 2 5 02/03/2011 09:25 60 6 02/03/2011 10:20 55 7 02/03/2011 10:34 14 Thanks! 回答1: If using SQL Server, one way is to do: DECLARE @Data TABLE (IDCode INTEGER PRIMARY KEY, DateVal DATETIME

Count number of Mondays in a given date range

孤街醉人 提交于 2019-12-17 06:09:07
问题 Given a date range, I need to know how many Mondays (or Tuesdays, Wednesdays, etc) are in that range. I am currently working in C#. 回答1: Try this: static int CountDays(DayOfWeek day, DateTime start, DateTime end) { TimeSpan ts = end - start; // Total duration int count = (int)Math.Floor(ts.TotalDays / 7); // Number of whole weeks int remainder = (int)(ts.TotalDays % 7); // Number of remaining days int sinceLastDay = (int)(end.DayOfWeek - day); // Number of days since last [day] if

Calculate date difference having a large range with PHP

扶醉桌前 提交于 2019-12-14 02:00:10
问题 I need to calculate the number of decades between 2 dates possible spanning form 1708 until today - the limitations are as far as I can gather are 1970/1901 within PHP native functions. Can anyone advise? Thanks! 回答1: If you have PHP >= 5.3.0: $before = new DateTime('1708-02-02'); $decades = $before->diff(new DateTime())->y / 10; 回答2: You could use Zend_Date. It's part of the Zend Framework but can be used standalone, you don't need to install the whole framework to use it. It can work with

sqlserver计算时间差DATEDIFF 函数

删除回忆录丶 提交于 2019-12-13 16:56:46
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 功能     返回两个日期之间的间隔。 语法     DATEDIFF ( date-part, date-expression-1, date-expression-2 ) date-part :     year | quarter | month | week | day | hour | minute | second | millisecond 参数     date-part 指定要测量其间隔的日期部分。   有关日期部分的详细信息,请参见日期部分。   date-expression-1 某一间隔的起始日期。从 date-expression-2 中减去该值,返回两个参数之间 date-parts 的天数。   date-expression-2 某一间隔的结束日期。从该值中减去 Date-expression-1,返回两个参数之间 date-parts 的天数。 注:一般在使用时间差判断时需要制定的 表达式>数字 ,方式,比例注册大于3天的会员 DATEDIFF(day,'xxx','xxx')>3,如果要小于制定天数或月份则 表达式<=数字; 注:若不是日期整数倍则截断 推荐方法:例如获取大于3个月的数据,当前时间向前推3个月,如果比注册时间大则,满3个月 用法    

DATEDIFF with minute does not return expected value

吃可爱长大的小学妹 提交于 2019-12-13 14:18:27
问题 Say, I have the following SQL Server 2008 table with data: CREATE TABLE tbl (dtIn DATETIME2, dtOut DATETIME2) INSERT tbl VALUES ('9/10/2012 5:14:10 AM', '9/10/2012 5:15:09 AM'), ('9/10/2012 5:16:12 AM', '9/10/2012 5:18:12 AM'), ('9/10/2012 5:18:43 AM', '9/10/2012 5:23:04 AM'), ('9/10/2012 5:25:17 AM', '9/10/2012 5:26:05 AM'), ('9/10/2012 5:26:57 AM', '9/10/2012 5:29:19 AM'), ('9/10/2012 5:31:41 AM', '9/10/2012 5:32:41 AM'), ('9/10/2012 5:33:16 AM', '9/10/2012 5:34:08 AM'), ('9/10/2012 5:35:25

Difference between dates - sql server

江枫思渺然 提交于 2019-12-12 19:18:10
问题 I need to get the following result between two dates: date_start = 01/01/2010 date_end = 10/21/2012 result: 1 year, 9 months and 20 days. I tried the code bellow, but it didn't work. It returns negative dates sometimes: SELECT CAST(DATEDIFF(yy, date_start, date_end) AS varchar(4)) +' year '+ CAST(DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy,date_start , date_end), date_start), date_end) AS varchar(2)) +' month '+ CAST(DATEDIFF(dd, DATEADD(mm, DATEDIFF(mm, DATEADD(yy, DATEDIFF(yy, date_start, date_end

Count the number of rows in 30 day bins

≯℡__Kan透↙ 提交于 2019-12-12 08:06:02
问题 Each row in my table has a date time stamp, and I wish to query the database from now, to count how many rows are in the last 30 days, the 30 days before that and so on. Until there is a 30 day bin going back to the start of the table. I have successfully carried out this query by using Python and making several queries. But I'm almost certain that it can be done in one single MySQL query. 回答1: No stored procedures, temporary tables, only one query, and an efficient execution plan given an