sqlite function for displaying month in Given Date?
-
28-05-2021 - |
题
I want display month in a given date by using sqlite date Functions.
For Example 30-March-2012.
I want display only March from that Date.
解决方案
In sqlite u can not get name of the month but you will get number of the month like 01-Jan ,02-Feb etc. You need to convert that number into month by code.
strftime('%m', dateField)
You will get number of month. And using case or nested if condition you can print month name.
其他提示
dateField is the date:
select case strftime('%m', dateField) when '01' then 'January' when '02' then 'Febuary' when '03' then 'March' when '04' then 'April' when '05' then 'May' when '06' then 'June' when '07' then 'July' when '08' then 'August' when '09' then 'September' when '10' then 'October' when '11' then 'November' when '12' then 'December' else '' end
as month
Try this
SELECT left(datename(month, DATEADD(MM,-1,getdate())), 3)
不隶属于 StackOverflow