Code Simplified – Viral Sarvaiya

Code Simplified – Viral Sarvaiya, Web Developer Friends, dot net Developer, Sql Server Developer

date-time-functions

Posted by Viral Sarvaiya on March 31, 2009

1) HERE IS MON DD YYYY HH:MIAM (OR PM) FORMAT ==>’ + CONVERT(CHAR(19),GETDATE())

2) HERE IS MM-DD-YY FORMAT ==>’ + CONVERT(CHAR(8),GETDATE(),10)

3) HERE IS MM-DD-YYYY FORMAT ==>’ + CONVERT(CHAR(10),GETDATE(),110)

4) HERE IS DD MON YYYY FORMAT ==>’ + CONVERT(CHAR(11),GETDATE(),106) PRINT ‘5)

HERE IS DD MON YY FORMAT ==>’ + CONVERT(CHAR(9),GETDATE(),6) PRINT ‘

HERE IS DD MON YYYY HH:MM:SS:MMM(24H) FORMAT ==>’ + CONVERT(CHAR(24),GETDATE(),113)

Here is the output from the above script:

1) HERE IS MON DD YYYY HH:MIAM (OR PM) FORMAT ==>Feb 5 2003 5:54AM

2) HERE IS MM-DD-YY FORMAT ==>02-05-03

3) HERE IS MM-DD-YYYY FORMAT ==>02-05-2003

4) HERE IS DD MON YYYY FORMAT ==>05 Feb 2003

5) HERE IS DD MON YY FORMAT ==>05 Feb 03

6) HERE IS DD MON YYYY HH:MM:SS:MMM(24H) FORMAT ==>05 Feb 2003 05:54:39:567

************************************************

select GETDATE()

select month(GETDATE())

select year(GETDATE())

select day(GETDATE())

************************************************

SELECT DAY(‘1/1/2003’), MONTH(‘1/1/2003’), YEAR(‘1/1/2003’), DATEPART(DAY, ‘1/1/2003’), DATEPART(MONTH, ‘1/1/2003’), DATEPART(YEAR, ‘1/1/2003’) ***************************************************

select GETDATE()

SELECT DATEPART(day, GETDATE())

SELECT DATEPART(month, GETDATE())

SELECT DATEPART(year, GETDATE())

SELECT DATEPART(hour, GETDATE())

SELECT DATEPART(minute, GETDATE())

SELECT DATEPART(second, GETDATE()) **************************************************

select CONVERT(CHAR(10),GETDATE(),101) 12/19/2007

select CONVERT(CHAR(10),GETDATE(),103) 19/12/2007 ***************************************************

lblDate.Text = String.Format(“{0:dd.MM.yyyy}”, System.DateTime.Now)

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: