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

05-07-04, 06:29
|
|
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:MI  S
Regards,
Thomas HO 
|
|

05-07-04, 06:48
|
|
Registered User
|
|
Join Date: Feb 2004
Location: Poland
Posts: 96
|
|
select CONVERT(CHAR(24),GETDATE(),120)
|
|

05-07-04, 10:02
|
|
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
|
|

05-09-04, 22:52
|
|
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.
|
|

05-09-04, 23:26
|
|
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
|
|

05-09-04, 23:49
|
|
Registered User
|
|
Join Date: May 2004
Posts: 14
|
|
Hi Ruby,
I'm using Sybase 12.5.1.
Regards,
Thomas HO
|
|

05-09-04, 23:59
|
|
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
|
|

05-10-04, 00:03
|
|
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:MI  S
|
|

05-10-04, 00:12
|
|
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?
|
|

05-10-04, 03:30
|
|
Registered User
|
|
Join Date: May 2004
Posts: 14
|
|
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!! 
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|