≡ Menu

How to extract date and time in Tsql

I extract date and time  from dateTime filed in TSQL as



CAST(CONVERT(varchar(8),vm_dm_StudentDet.Dep,112) AS int) DepDate,
Cast(CONVERT(VARCHAR(8),vm_dm_StudentDet.Dep,108) AS time) DepTime,
Cast(CONVERT(VARCHAR(8),vm_dm_StudentDet.Dep,101) as date) dt
from vm_dm_StudentDet

if you test this on current date you use as follow.


CAST(CONVERT(varchar(8),GETDATE(),112) AS int) DepDate,
Cast(CONVERT(VARCHAR(8),GETDATE(),108) AS time) DepTime,
Cast(CONVERT(VARCHAR(8),GETDATE(),101) as date) dt

Comments on this entry are closed.