all groups > sql server programming > november 2006 >
You're in the

sql server programming

group:

convert varchar to datetime



convert varchar to datetime vanitha
11/5/2006 9:56:03 PM
sql server programming: hi,

i want to convert varchar to datetime

example

i want the first date of the month.

convert(datetime,'01-'+month(getdate())+'-'+year(getdate()))

its not working for me.

pls do help me solve this.

thank you
RE: convert varchar to datetime Krishnakumar S
11/5/2006 10:07:01 PM
Month and Year function returns INT. So CAST the result to VARCHAR and
concatenate

This may help
SELECT convert(datetime,'01-'+ CAST(month(getdate()) AS
VARCHAR)+'-'+CAST(year(getdate()) AS VARCHAR))
--
Krishnakumar S


[quoted text, click to view]
Re: convert varchar to datetime Uri Dimant
11/6/2006 12:00:00 AM
Hi
SELECT DATEADD(MONTH,DATEDIFF(MONTH,0,GETDATE()),0)


[quoted text, click to view]

AddThis Social Bookmark Button