The SQLite julianday function facilitates you to apply modifiers and then returns the date as a Julian Day after taking the date as an input.
A Julian Day is the number of days since Nov 24, 4714 BC 12:00pm Greenwich time in the Gregorian calendar. The julianday function returns the date as a floating point number.
Syntax:
julianday(timestring [, modifier1, modifier2, ... modifier_n ] )
Example1: Retrieve current date:
SELECT julianday('2017-04-13'); SELECT julianday('2017-04-13 16:45'); SELECT julianday('2017-04-13 16:45:30'); SELECT julianday('now');
Output:
Example2: Retrieve First Day of the Month:
SELECT julianday('2017-04-13', 'start of month'); SELECT julianday('now', 'start of month'); SELECT julianday('2017-03-13', '-6 days'); SELECT julianday('now', '-6 days');
Output:
Example2: Retrieve Last Day of the Month:
SELECT julianday('2017-03-07', 'start of month', '+1 month', '-1 day'); SELECT julianday('now', 'start of month', '+1 month', '-1 day'); SELECT julianday('2017-03-07', '+24 days'); SELECT julianday('now', '+24 days');
Output:
Example3: Add/ subtract years/ days on the current date:
SELECT julianday('2017-04-14', '+2 years'); SELECT julianday('now', '+5 years'); SELECT julianday('now', '-7 days');
Output: