If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > using convert function for date in transact sql

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 05-07-04, 06:29
thomasmsho thomasmsho is offline
Registered User
 
Join Date: May 2004
Posts: 14
using convert function for date in transact sql

Dear all,

Is there any one know how to use CONVERT function in TSQL to convert the datetime field into the following format.

YYYY/MM/DD HH24:MIS

Regards,

Thomas HO
Reply With Quote
  #2 (permalink)  
Old 05-07-04, 06:48
rafala rafala is offline
Registered User
 
Join Date: Feb 2004
Location: Poland
Posts: 96
select CONVERT(CHAR(24),GETDATE(),120)
Reply With Quote
  #3 (permalink)  
Old 05-07-04, 10:02
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
Depending on how picky you are, you might prefer:
Code:
SELECT Replace(Convert(CHAR(19), GetDate(), 120), '-', '/')
-PatP
Reply With Quote
  #4 (permalink)  
Old 05-09-04, 22:52
thomasmsho thomasmsho is offline
Registered User
 
Join Date: May 2004
Posts: 14
Sorry, but I get the following error message:-

Line 4:
120 is not a valid style number when converting from DATETIME to a character string.
Reply With Quote
  #5 (permalink)  
Old 05-09-04, 23:26
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
????? what version of sql server?

i use 120 all the time, it's my favourite, it's the ISO standard
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #6 (permalink)  
Old 05-09-04, 23:49
thomasmsho thomasmsho is offline
Registered User
 
Join Date: May 2004
Posts: 14
Hi Ruby,

I'm using Sybase 12.5.1.

Regards,

Thomas HO
Reply With Quote
  #7 (permalink)  
Old 05-09-04, 23:59
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
sorry, i keep forgetting that there are actually two completely different databases, both coincidentally called sql server

you're right, sybase's does not apeear to supoprt style 120

see http://manuals.sybase.com/onlinebook...uery=convert#X

note that only two styles include the time
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #8 (permalink)  
Old 05-10-04, 00:03
thomasmsho thomasmsho is offline
Registered User
 
Join Date: May 2004
Posts: 14
Ruby,

Do you mean I have no way to convert a datetime into the following format:-

YYYY/MM/DD HH24:MIS
Reply With Quote
  #9 (permalink)  
Old 05-10-04, 00:12
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
please, the name is Rudy -- "Ruby" once is a typo, twice is an error

yes, you can get the format you want, but it may take several functions

do you have a manual?
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #10 (permalink)  
Old 05-10-04, 03:30
thomasmsho thomasmsho is offline
Registered User
 
Join Date: May 2004
Posts: 14
Talking

Thanks Rudy!

I manage to do it with the following:-

SELECT Convert(CHAR(10), GetDate(), 111)+' '+Convert(CHAR(8),GetDate(),108)


Thanks a lot !!!!

Bye!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On