How to get date function in sql as ddmmyyyyhhmmss rather than dd/mm/yyyy
Problem :--- How to get date function in sql as ddmmyyyyhhmmss rather than dd/mm/yyyy
- Please see we use Get Date() in sql to get the current date value showing date on our PC.
- Use Replace for
- Use Convert for
- Use substring for
DIY!
Firstly, try fetching only the current date in your sql server
Result 2017-10-23 13:34:22.617
Do you want to trim time? Use this or skip step
Do you need Hiphens? if not skin this step
- select replace(convert(varchar(14),getdate(),103), '/','')
result --- 23102017
Ways to fetch time
- select convert(char(5), getdate(), 108) [time]
Result:14:30
Final Query to get date and time by DDMMYYYYHHMMSS
- select replace(convert(varchar(14),getdate(),103), '/','') + substring(CONVERT(VARCHAR(10),GETDATE(),103),4,2)+ REPLACE(CONVERT(varchar(5),getdate(),108),':','')
REsult: 23102017101431






0comments
Post a Comment