Ways of getting different different date formats

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 198
Following are the ways of getting different different date formats in sql server:-

select convert(varchar(10),getdate(),101) as date_only_MM_dd_yyyy;
Output:
06/28/2014


select cast(getdate() as varchar(20)) as date_time_MMM_dd_year_hh:mm_AM_PM;
Output:-
Sat 28 2014 6:25PM


Select dateadd(dd,datediff(dd,Getdate(),0),Getdate());
Output:
1900-01-01 18:51:33.863


Using convert function:-
select convert (date, getdate()) 'date part only_yyyy_MM_dd';
Output:
2014-06-28


Another way Using cast function:-
select cast(getdate() as date) 'date part only_yyyy_MM_dd';
Output:
2014-06-28

Comments or Responses

Login to post response