Use sql server Convert Function to convert hijri to gregorian date

烈酒焚心 提交于 2019-12-23 02:43:10

问题


I have simple table on my sql server and in my table have a date field,and into date field save a hijri date,i want use the sql server convert function to convert hijri date to gregorian date.
how can i do this?
i use this query in sql server:

update k
set time=CONVERT(datetime,GETDATE(),101)

and i insert this "1392/4/21" in time field ,and when convert sql server return this "2014/11/5",when i use online date convertor,and insert this "2014/11/5",convert date is "1393/2/14" !!is this the correct resualt?


回答1:


Here is a sample how you could do it:

select convert(datetime, value, 131)
from (
    values ('13/01/1436  9:54:59:767AM')
    ) samples(value)

There are several blogs about this, likethis one: http://blogs.msdn.com/b/wael/archive/2007/04/29/sql-server-hijri-hijra-dates.aspx

and this one: http://raresql.wordpress.com/2013/05/08/sql-server-how-to-convert-gregorian-dates-to-hijri-date-with-formatting/



来源:https://stackoverflow.com/questions/26749403/use-sql-server-convert-function-to-convert-hijri-to-gregorian-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!