Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATETIME Parser routine 1

Status
Not open for further replies.

btturner

Programmer
May 17, 2001
175
US
Trying to get SQL Server's returned DATETIME format:
2001-05-15 10:32:23.670

parsed into 2 seperate columns, a DATE and a TIME..

my_Date_Column: 2001-05-15
my_Time_Column: 10:32:23.670 (microsec's not req'd)

anyone have a routine which PARSEs the DATETIME value returned by SQL??

thx, Bill
 
Hi use the convert function of SQL*SERVER
First convert it to VARCHAR(30).
And then convert it to a date or time value.

See Books online for syntax and value of parameter

Example is
CONVERT(VARCHAR(30), fieldname, 105) returns dd-mm-yy format.

Hope this helps

JNC73
 
thx JNC but I need the date in format yyyy-mm-dd (w/out any timestamp appended) In sql 2k, I see know CONVERT function available to return just the date in this format...
 
FYI: No need to convert to varchar(30) to parse the datetime.

Select convert(char(10),getdate(),120) AS my_Date_Column, Convert(char(12),getdate(),114) my_Time_Column

my_Date_Column would contain current date in yyyyy-mm-dd format
my_Time_Column would contain current time in hh:mi:ss.mmm format Terry

;-) The single biggest challenge to learning SQL programming is unlearning procedural programming. -Joe Celko

SQL Article links:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top