I am trying to get the Hijri GETDATE() and convert it into this format yyyymmdd
I have already tried this script
SELECT CONVERT(VARCHAR(10), GETDATE(), 131)
but it gives me this format ( 16/06/1438 ) and what I actually need is (1438/06/16)
SQL Server GETDATE() Function The GETDATE() function returns the current database system date and time, in a 'YYYY-MM-DD hh:mm:ss. mmm' format. Tip: Also look at the CURRENT_TIMESTAMP function.
You can specify the format of the dates in your statements using CONVERT and FORMAT. For example: select convert(varchar(max), DateColumn, 13), format(DateColumn, 'dd-MMM-yyyy')
SQL Server does not offer a wealth of formatting options for such dates, so just construct it yourself:
SELECT (RIGHT(CONVERT(VARCHAR(10), GETDATE(), 131), 4) + '/' +
CONVERT(VARCHAR(5), GETDATE(), 131)
) as hj_yyyymmdd
Oops. Right idea, wrong implementation:
SELECT (RIGHT(CONVERT(VARCHAR(10), GETDATE(), 131), 4) +
SUBSTRING(CONVERT(VARCHAR(10), GETDATE(), 131), 3, 4) +
LEFT(CONVERT(VARCHAR(10), GETDATE(), 131), 2)
) AS hj_yyyymmdd
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With