![]() First, we use the 'start of month' modifier to calculate the first day of the month and then add 1 month and then subtract 1 day. In these examples, we've calculated the last day of the month in a few different ways. Sqlite> SELECT date('now', 'start of month','+1 month', '-1 day') You could retrieve the last day of the month using the date function as follows: sqlite> SELECT date('', 'start of month','+1 month', '-1 day') Since we had a date value of the, this returns the first day of the month (ie: ). In our examples, we subtracted 15 days from our date values. We can also add or subtract days to a date value using the ' NNN day' modifier. This includes using the 'now' timestring. The 'start of month' modifier lets us take any date value and calculate the first day of the month for that date. In these examples, we've calculated the first day of the month in a few different ways. Sqlite> SELECT date('now', 'start of month') You could retrieve the first day of the month using the date function as follows: sqlite> SELECT date('', 'start of month') Result: '' (formatted as YYYY-MM-DD) First Day of the Month Example You could retrieve the current date in SQLite using the "now" timestring with the date function as follows: sqlite> SELECT date('now') Let's look at some SQLite date function examples and explore how to use the date function in SQLite. Used with the DDDDDDDDDD timestring to interpret the date as UNIX Time (ie: number of seconds since )Īdjusts date to localtime, assuming the timestring was expressed in UTCĪdjusts date to utc, assuming the timestring was expressed in localtime (0=Sunday, 1=Monday, 2=Tuesday, 3=Wednesday, 4=Thursday, 5=Friday, 6=Saturday) Moves the date forward to the next date where weekday number is N Shifting the date back to the start of the day Shifting the date back to the start of the month Shifting the date back to the start of the year Number of seconds (and fractional seconds) added/subtracted to the date Number of seconds added/subtracted to the date ![]() Number of minutes added/subtracted to the date ![]() Number of hours added/subtracted to the date ![]() Number of days added/subtracted to the date Number of months added/subtracted to the date Number of years added/subtracted to the date They can be one or more of the following: Each modifier is applied in order and are cumulative. These are modifiers that are applied to the timestring. Now is a literal used to return the current date.ĭate value formatted as 'YYYY-MM-DD HH:MM'ĭate value formatted as 'YYYY-MM-DD HH:MM:SS'ĭate value formatted as 'YYYY-MM-DD HH:MM:SS.SSS'ĭate value formatted as 'YYYY-MM-DD THH:MM' where T is a literal character separating the date and time portionsĭate value formatted as 'YYYY-MM-DD THH:MM:SS' where T is a literal character separating the date and time portionsĭate value formatted as 'YYYY-MM-DD THH:MM:SS.SSS' where T is a literal character separating the date and time portions ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |