Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Date reformat question for the group

 
   Database Forums (Home) -> MSEQ RSS
Next:  Backup remote database  
Author Message
Graham

External


Since: May 02, 2007
Posts: 1



(Msg. 1) Posted: Tue May 15, 2007 10:42 am
Post subject: Date reformat question for the group
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

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.

--
Graham (Pete) Berry
PeteBerry.TakeThisOut@CalTech.edu

 >> Stay informed about: Date reformat question for the group 
Back to top
Login to vote
JPD

External


Since: Jun 19, 2007
Posts: 18



(Msg. 2) Posted: Tue Jul 17, 2007 8:55 am
Post subject: Re: Date reformat question for the group [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

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.
>

 >> Stay informed about: Date reformat question for the group 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
question on date (or string after using convert function) .. - select case when '02/12/2005' >= '01/02/2006' then 'T' else 'F' end the result return is 'T' why?? (2005 should be < 2006)

Update 'Date': Set Day(Date) to a Certain Number - Hi, I am trying to use an update command to set the day of a date to a certain number. For example, if the date is 1/4/06, I might want to set day(date) to '7'. So it turns into 1/7/06. I wasn't sure if there was a way to do this and I keep getting....

How to "avoid" a GROUP BY - HAVING - I have four tables, 1. First has Items, 2. Second has Features, 3. Third defines the ItemsFeatures 4. And temporary that sets which Items have to SELECT according Features For this statment we do not need table(2), IF (SELECT COUNT(*) FROM..

GROUP BY's on 3 tables in one SELECT? - Hi there, I'd like to ask you for help with following: having 3 tables: T1 (Person_ID, Product_ID, Costs) T2 (Person_ID, Product_ID, Balancies) T3 (Product_ID, Product_Type) I have simple GROUP BY query: SELECT T1.Person_ID, T1.Product_ID, MAX(Costs)..

How to select all top 1s from different group in a view - Hi SQL Query Guru, I have a view like this: Contract_KEY Step 1 1 1 3 2 1 2 5 2 4 How do I write a query to retrieve the following result: ...
   Database Forums (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]