Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6949123
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:54:48+00:00 2026-05-27T13:54:48+00:00

I am writing some T-SQL which needs to enforce a minimum date value onto

  • 0

I am writing some T-SQL which needs to enforce a minimum date value onto some null fields:

DECLARE @epoch DATETIME;
set @epoch='1900-01-01';
select min = ISNULL(ValidFromDate,@epoch)

Is the string ‘1900-01-01’ always going to return a datetime of Jan 1 1900 in any environment or will SQL server try to parse the string according to local culture rules?

If that’s not good enough, what is the recommended way of specifying a particular date/time in T-SQL?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:54:48+00:00Added an answer on May 27, 2026 at 1:54 pm

    The best format for string-based dates is the ISO-8601 standard format.

    For DATETIME variables and columns, this is either YYYYMMDD (for dates without time; without any dashes!) or YYYY-MM-DDTHH:MM:SS (date + time).

    Contrary to popular belief, YYYY-MM-DD for DATETIME variables is NOT language-/dateformat-independent! If you try this, the second CAST will result in an error:

    SET LANGUAGE us_english
    SELECT CAST('2011-07-20' AS DATETIME)
    
    SET LANGUAGE british
    SELECT CAST('2011-07-20' AS DATETIME)
    

    but this will work:

    SET LANGUAGE british
    SELECT CAST('20110720' AS DATETIME)
    

    This is the best format since it’s indepdendent of your language and dateformat settings in SQL Server.

    For SQL Server 2008 and columns of type DATE (just date – no time), the format can also be YYYY-MM-DD (with the dashes) and that works for all settings, too.

    Why there is such a difference between DATE and DATETIME is beyond me – that’s just the way it is for now!

    See Tibor Karaszi’s excellent The Ultimate Guide to the DateTime data types for even more details and examples.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a PL/SQL procedure that needs to to dynamically generate some queries,
I am writing a plugin (my first) for CRM2011 which needs to pull some
I am writing some new SQL queries and want to check the query plans
Say I'm writing some ruby code and I want to use the standard Date
I have seen majority of web programmers (writing some script with sql to make
I'm writing a query in SQL in which i have to find the youngest
I'm writing a Rails application which will monitor data quality over some specific databases.
Writing some test scripts in IronPython, I want to verify whether a window is
While writing some C code, I decided to compile it to assembly and read
I was writing some ASP.NET control when I came to the scenario where I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.