Formatted output of date and time field in SELECT query of MSSQL table
We 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 " , conn
Inside the convert command char(8) will collect first 8 characters of time part so it will display like this
So 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 " , conn
From above command we will get the output like this.
This 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.