February 2, 2006 at 6:48 pm
This will successfully convert characters in the DD/MM/YYYY format into a DateTime datatype without much fanfare...
CONVERT(DATETIME, yourstringdate, 103)
Here's an example you can try...
DECLARE @ddmmyyyyString CHAR(10)
SET @ddmmyyyyString = '25/01/2006'
DECLARE @MyDateTime DATETIME
SET @MyDateTime = CONVERT(DATETIME,@ddmmyyyyString,103)
SELECT @MyDateTime
--Jeff Moden
Change is inevitable... Change for the better is not.
February 2, 2006 at 6:52 pm
I just gotta remember to read the last page ... Serqiy already made a similar suggestion. Guess a concurrence never hurts though...
--Jeff Moden
Change is inevitable... Change for the better is not.
February 3, 2006 at 2:43 am
If you want to guarantee that Regional Settings (of the user, the workstation, or the server) do not cause havoc with your dates, I highly recommend passing dates to the SP in the format:
dd-mmm-yyyy
For example
03-FEB-2006
MSSQL will always correctly convert this string to DATETIME, irrespective of Regional Settings. There is no chance of this date being interpreted as 2nd March, for example.
February 3, 2006 at 2:58 am
February 3, 2006 at 3:25 am
hmm, good point. However, the main problem here is the variation between US date format, rest-of-world date format (ok, not quite true) and ISO date format.
I would like to recommend ISO standard, but in my experience I have had odd results (mainly with Microsoft Access database, it must be said), but sufficient to put me off using it.
I would also suggest that none of the solutions here would work with the Chinese calendar (which is far more complex than just saying it is now the year of the dog).
February 3, 2006 at 11:39 am
If you use the yyyymmdd format, it will always work regardless of the regional settings or SET DATEFORMAT state. Plus, no U.S. month names, just numbers. Since today is Feb 3, 2006, you would use '20060203'
February 5, 2006 at 10:31 pm
instead of going concatinating like this
@EndDate + '23:59:00.000'
you can use convert function and then convert to sepcified format
say
CONVERT(DATETIME,CONVERT(VARCHAR,getdate(),101),101)
gives the following format.
2006-02-06 00:00:00.000
hope this will helpfull.
Dhanu 🙂
Viewing 7 posts - 16 through 21 (of 21 total)
You must be logged in to reply to this topic. Login to reply