Current Time in Query

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

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

SELECT GETDATE() AS CurrentDateTimeCurrentDateTime             --------------------------- 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 CurrentDateTimeCurrentDateTime
---------------------July 10, 2000 12:50

Share the Post:
Share on facebook
Share on twitter
Share on linkedin


Recent Articles: