What is the most straightforward way to pad empty dates in sql results (on either mysql or perl end)?

When you need something like that on server side, you usually create a table which contains all possible dates between two points in time, and then left join this table with query results. Something like this: create procedure sp1(d1 date, d2 date) declare d datetime; create temporary table foo (d date not null); set d … Read more

Twig date difference

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 %} {{ … Read more

Python: Difference of 2 datetimes in months [duplicate]

You could use python-dateutil. In [4]: from datetime import datetime In [5]: date1 = datetime.strptime(str(‘2011-08-15 12:00:00’), ‘%Y-%m-%d %H:%M:%S’) In [6]: date2 = datetime.strptime(str(‘2012-02-15’), ‘%Y-%m-%d’) In [7]: from dateutil import relativedelta In [8]: r = relativedelta.relativedelta(date1, date2) In [9]: r Out[9]: relativedelta(months=-5, days=-30, hours=-12)

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

You can convert the duration to a date and then format it: DECLARE @FirstDate datetime, @LastDate datetime SELECT @FirstDate=”2000-01-01 09:00:00″, @LastDate=”2000-01-01 11:30:00″ SELECT CONVERT(varchar(12), DATEADD(minute, DATEDIFF(minute, @FirstDate, @LastDate), 0), 114) /* Results: 02:30:00:000 */ For less precision, modify the size of the varchar: SELECT CONVERT(varchar(5), DATEADD(minute, DATEDIFF(minute, @FirstDate, @LastDate), 0), 114) /* Results: 02:30 */

DATEDIFF function in Oracle [duplicate]

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-02’, ‘YYYY-MM-DD’) – TO_DATE(‘2000-01-01’, ‘YYYY-MM-DD’) AS DateDiff FROM … Read more