Date and Time Strings Examples

Date Formats :
Date Format       YYYY-MM-DD
Date Time Format  YYYY-MM-DD HH:MI:SS
Time Stamp Format YYYY-MM-DD HH:MI:SS

ex:if you query a datetime with :
   WHERE PURCHASEDATE='2016-12-12'
   --you will get no results
So always know the format first.

Sql Date time Functions :
Date(),Time(),Datetime(),Julianday(),Strftime() .

Using String Format Time Function :
select Birthdate,
       strftime('%Y',Birthdate) as YEAR,
       strftime('%m',Birthdate) as MONTH,
       strftime('%d',Birthdate) as DAY,
       strftime('%H %M %S',Birthdate) as hour_min_sec,
       Date(('now')-Birthday) as age,
from data1;

>>select date('now') --will return the current date     
select strftime('%Y %m %d','now') --will also return current date
--remember current date is very useful for calculating age and stuff.
>>select strftime('%H %M %S %s',now) as hour_min_sec_millisec

Do check out for more exploration :
https://www.w3schools.com/SQl/sql_dates.asp
https://www.w3schools.com/sql/sql_datatypes.asp

Comments

Popular Posts