SQL Server datetime

10 pts.
Tags:
SQL datetime
SQL Server 2000
SQL Troubleshooting
Hi - When I run this: select cast ('461129' as datetime) i get 2046-11-29 00:00:00.000 instead of 1946-11-29 00:00:00.000 Can you please let me know why and what I need to do in order to get the required results. thx

Answer Wiki

Thanks. We'll let you know when a new response is added.

You’ll need to specify the value in an accepted format.

<pre>select cast (’19461129′ as datetime)</pre>

———–

The default cutoff year for two-digit years is 2049 (i.e. Sql Server interprets two-digit years as being between 1950 and 2049).

I don’t know if there is some other way to get the results you need, but you may need to change this option in the database. (for compatibility, it is not recommended to modify it)

Have a look at the following page for instructions on how to do it in Sql Server 2000:

<a href=”http://msdn.microsoft.com/en-us/library/aa177108(SQL.80).aspx”>How to set the two digit year cutoff option (Enterprise Manager)</a>

———- kccrosser

Changing the defaults on your database is a bit risky, as it will affect how other applications behave. A better approach (if you have to deal with 6-digit date strings) is to write a function to apply some rational processing to the string before converting it. Most applications that accept 2-digit years apply a +25/-75 rule – if adding the current century yields a date that is less than 25 years in the future, use that da

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • msi77
    > i get 2046-11-29 00:00:00.000 instead of 1946-11-29 00:00:00.000 Maybe you need 1846 or 1546? :-) Four-digit year representation is for that.
    1,660 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following