Tutorial by Examples

Select Now(); Shows the current server date and time. Update `footable` set mydatefield = Now(); This will update the field mydatefield with current server date and time in server's configured timezone, e.g. '2016-07-21 12:00:00'
NOW() + INTERVAL 1 DAY -- This time tomorrow CURDATE() - INTERVAL 4 DAY -- Midnight 4 mornings ago Show the mysql questions stored that were asked 3 to 10 hours ago (180 to 600 minutes ago): SELECT qId,askDate,minuteDiff FROM ( SELECT qId,askDate, TIMESTAMPDIFF(MINUTE,askDate,no...
Although it is very tempting to use BETWEEN ... AND ... for a date range, it is problematical. Instead, this pattern avoids most problems: WHERE x >= '2016-02-25' AND x < '2016-02-25' + INTERVAL 5 DAY Advantages: BETWEEN is 'inclusive' thereby including the final date or second. 2...
SELECT SYSDATE(); This function returns the current date and time as a value in 'YYYY-MM-DD HH:MM:SS' or YYYYMMDDHHMMSS format, depending on whether the function is used in a string or numeric context. It returns the date and time in the current time zone. SELECT NOW(); This function is a...
SELECT DATE('2003-12-31 01:02:03'); The output will be: 2003-12-31
Many real-world database tables have many rows with DATETIME OR TIMESTAMP column values spanning a lot of time, including years or even decades. Often it's necessary to use a WHERE clause to retrieve some subset of that timespan. For example, we might want to retrieve rows for the date 1-September-2...

Page 1 of 1