Formatted output of date and time field in SELECT query of MSSQL tableWe may have to collect date and time in different formats based on our requirement. While using a SELECT query we can specify our format by using CONVERT . Here is an examples of collecting different types of date and time.
only time part
rs.open " select convert(char(8),issue_dt,108) as tmp from dt " , connInside the convert command char(8) will collect first 8 characters of time part so it will display like this
22:02:00So a value of char(5) will only display hour and minutes ( no seconds ) and char(2) will display only hours
Only Date Part
rs.open " select convert(char(10),issue_dt,101) as tmp from dt " , connFrom above command we will get the output like this.
12/22/2007This is in US date format or mm/dd/yyy format
Here is the table for different style values can be sued along with convert to get required date and time formats.
This article is written by plus2net.com team.
Be the first to post comment on this article :