Link to home
Start Free TrialLog in
Avatar of DavidNPD
DavidNPD

asked on

Convert Date Format in SQL Query

I would like to convert the format of a DateTime field in sql. Currently the field (rec_dt) holds a value such as this "4/6/2006 1:08:48 PM" I would like this to be shown in the query as 04/06/06 1308"

I was trying to use a command such as the one below, but I dont think I have the format correct.


SELECT     cfs_no, rec_dt, CONVERT(datetime, rec_dt, 103) AS NewDate
FROM         dba.cfs
Avatar of SjoerdVerweij
SjoerdVerweij

SELECT     cfs_no, rec_dt, CONVERT(varchar, rec_dt, 103) AS NewDate
FROM         dba.cfs
Hi DavidNPD,

Select  cfs_no, rec_dt, convert(varchar,rec_dt,103) + ' ' + convert(varchar(5),rec_dt,114) As NewDate
FROM         dba.cfs

Tim Cottee
Avatar of DavidNPD

ASKER

That is really close, but I have a field size issue that I really need to trim down. I am seeing "06/04/2006 11:21" right now, is there a way to make the 2006 only 06 and also to trim out the :

TimCottee
I just realized that the month and day is now swapped, it is no longer 04/06/2006 but 06/04/2006.

SjoerdVerweij,
that just gives me "06/04/2006", no time and also the swapped month/day
ASKER CERTIFIED SOLUTION
Avatar of SjoerdVerweij
SjoerdVerweij

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial