Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Jul 14, 2000

Current Time in Query

Question:
Can I include something in the title line of a query to include the current date/time?

Answer:
You can use the GETDATE() function to return the current date and time like this:

SELECT GETDATE() AS CurrentDateTime

CurrentDateTime             
--------------------------- 
2000-07-10 12:50:57.000
If the GETDATE() function doesn't return the date in the format you want, you can reformat it. This is just one example of how you can use the date and time functions to reformat the date:
SELECT (DATENAME(month, GETDATE()) + " " + 
        DATENAME(dd, GETDATE()) + ", " +
        DATENAME(yy, GETDATE()) + " " +
        DATENAME(hh, GETDATE()) + ":" +
        DATENAME(mi, GETDATE()))  
  AS CurrentDateTime

CurrentDateTime
--------------------- July 10, 2000 12:50
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date