You just need to substitute date1 and date2 with your date expressions.
NOTE: Some of these formulas are complex because they account for all cases where date1 date2.
Additionally, these formulas can be used in very generic queries where aliases and temporary variables are not allowed.
Return values from temporal functions include fractional seconds as appropriate.
function reliable when combined with other functions that extract a date part from a date.
If you prefer a result evaluated with respect to the year that contains the first day of the week for the given date, use PDF (US Ltr) - 35.4Mb PDF (A4) - 35.4Mb PDF (RPM) - 34.5Mb EPUB - 8.7Mb HTML Download (TGZ) - 8.5Mb HTML Download (Zip) - 8.5Mb HTML Download (RPM) - 7.3Mb Eclipse Doc Plugin (TGZ) - 9.3Mb Eclipse Doc Plugin (Zip) - 11.4Mb Man Pages (TGZ) - 200.4Kb Man Pages (Zip) - 305.7Kb Info (Gzip) - 3.3Mb Info (Zip) - 3.3Mb My SQL Backup and Recovery My SQL Globalization My SQL Information Schema My SQL Installation Guide My SQL and Linux/Unix My SQL and OS X My SQL Partitioning My SQL Performance Schema My SQL Replication Using the My SQL Yum Repository My SQL Restrictions and Limitations Security in My SQL My SQL and Solaris Building My SQL from Source Starting and Stopping My SQL My SQL Tutorial My SQL and Windows My SQL Cluster NDB 7.5 If you're looking for generic SQL queries that will allow you to get the days, months, and years between any two given dates, you might consider using these.
This section describes the functions that can be used to manipulate temporal values.
See Section 12.3, “Date and Time Types”, for a description of the range of values each date and time type has and the valid formats in which values may be specified.
The query also selects rows with dates that lie in the future.
Functions that expect date values usually accept datetime values and ignore the time part.
Functions that expect time values usually accept datetime values and ignore the date part.
Functions that return the current date or time each are evaluated only once per query at the start of query execution.