ORDER BY Date Order
ASC = oldest first
DESC = most recent first
Note it’s “MINUTE”, “HOUR”, etc not “MINUTES” or “HOURS” etc
Convert DateTime to Date
CAST('$EventDateTime'AS DATE)
Specifying Date and DateTime from a string
It is recommended to use CAST()
CAST('$Year-$Month-01' AS DATE)
CAST('$Year-$Month-01T00:00:00' AS DATE)
CAST('$Year-$Month-01T00:00:00' AS DATETIME)
Last Day Of Month
(This produces a DATE result, not DATETIME)
LAST_DAY('2019-01-01T00:00:00')
//Will produce '2019-01-31'
Get SQL Server’s Current DateTime
//Get the sqlserver current datetime
$query = mysqli_query($dblink, "SELECT *, NOW() as datetimenow FROM tblMyTable WHERE Id = 1");
$Result = mysqli_fetch_array($query, MYSQLI_ASSOC);
$DateTimeNow = $Result['datetimenow'];
Same as Now() but giving just the date:
CURDATE()
How is DateTime stored by MySQL?
From the 10.9 Date and Time Data Type Representation:
1 bit sign (1= non-negative, 0= negative)
17 bits year*13+month (year 0-9999, month 0-12)
5 bits day (0-31)
5 bits hour (0-23)
6 bits minute (0-59)
6 bits second (0-59)
---------------------------
40 bits = 5 bytes
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.