Re: Date reformat question for the group



Hi,

Assuming you're using SQL Server 2005, have you tried using the DATEPART function?

Jonathan



Graham (Pete) Berry wrote:
I hope I am posting this in the correct group, but if not please tell me the proper place. I am more of an admin type than a developer and am having a problem I have been unable to code around. In short, what I want to do is convert today's date and time into a series of local numerical character variables

YYYY
MM (with a leading 0 if LT 10)
DD (with a leading 0 if LT 10)
HH (24-hour format)
SS

This format is equivalent to a CONVERT function style code of 120 with the separators removed.

Tried various combinations of SUBSTRING and CONVERT functions, but they did not work. For example the SUBSTRING can only handle CHAR/VARCHAR type data. Then the GETDATE() function represents the internal DATETIME format as

MMM DD YYYY HH:MMAM or
MMM DD YYYY HH:MMPM

where the leading D=0 and H=0 are omitted. The YEAR and DAY functions work but also omit any leading zero's and there is no corresponding HOURS or MINUTES function

Any coders out there with a suggested solution as to how I can do this? I've run out of ideas and BOL hasn't helped.

.