February 23, 2011 at 2:22 pm
Hi,
How would represent date for 15th feb 2011 12 a.m in the same format as getdate() does?
will it be something like this in sql server 2005
'2011-02-15 00:00:00.000'
Please help
Thanks,
February 23, 2011 at 4:02 pm
In short, yes.
Try this:
SELECT CONVERT(DATETIME,'15 Feb 2011 12 am',121) as my_date ;
There are no special teachers of virtue, because virtue is taught by the whole community.
--Plato
February 23, 2011 at 4:20 pm
Pink123 (2/23/2011)
Hi,How would represent date for 15th feb 2011 12 a.m in the same format as getdate() does?
will it be something like this in sql server 2005
'2011-02-15 00:00:00.000'
Please help
Thanks,
The following can easily be modified to do a whole table provided that the table contains the same type of date markings (1st, 2nd, 3rd, 4th, etc). It will produce incorrect dates for other formats.
DECLARE @YourDate VARCHAR(50);
SELECT @YourDate = '15th feb 2011 12 a.m';
WITH
cteFindPositions AS
(
SELECT Original = @YourDate,
StartPos = PATINDEX('%[0-9][a-z]%',@YourDate)+1,
EndPos = PATINDEX('% [a-z]%',@YourDate)
)
SELECT CAST(REPLACE(STUFF(Original, StartPos, EndPos-StartPos,''),'.','') AS DATETIME)
FROM cteFindPositions
;
--Jeff Moden
Change is inevitable... Change for the better is not.
February 24, 2011 at 7:16 am
Thanks for the reply.It helped me
February 25, 2011 at 5:09 pm
You bet. Thanks for the feedback.:-)
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy