When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs



















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

.Net Developer
Professional Technical Resources
US-WA-Bellingham

Justtechjobs.com Post A Job | Post A Resume

Published: Tuesday, April 10, 2001

Working with Databases and International Date Formats
By Darren Neimke


Workaround for Non-English Countries
Darren's article works wonders for international, English-speaking countries, like England, the United States, Australia, and so on. However, in non-English speaking countries, the months of the year are spelled differently and, hence, have different abbreviations. If you are from a non-English speaking country you may wish to read Giuliano Sauro's article: Using the ISO Date Format for International Dates.

- continued -

For general answers to your date/time questions, be sure to check out the Date and Times FAQ Category on ASPFAQs.com!

If you've ever written a script that needs to UPDATE or INSERT Date values in a database and you live outside of North America, then I'd nearly bet that (like me) you've stayed up until midnight cursing the fact that all dates in SQL Server and MS-Access are natively converted from US date format (mm/dd/yyyy).

Why is that a problem I hear you ask? Simple, I'll tell you the answer to that question on 6/4/2001. Did you see that? No? OK then, what is 6/4/2001? Well if you are converting dates using mm/dd/yyyy format then the answer would be the 4th-Jun-2001. On the other hand if you were converting dates using dd/mm/yyyy format (as is the case in Australia and the UK) then the answer would be 6th-Apr-2001. To see what I mean, if we copy this code into an ASP page and run it:

'English - United States LCID
Session.LCID = 1033
Response.Write Date() & "<br />"

'English - Australia LCID
Session.LCID = 3081
Response.Write Date() & "<br />" 

the results are:

4/10/2001
10/04/2001

For more information on using Session.LCID to alter locale-specific information, be sure to read: Using the Locale Identifier (LCID). You can view a list of all of the valid LCIDs here.

Now, before I explain how to remedy the problem, which, incidentally I already have anyway ;), first let's try to get a better understanding of what exactly is happening. Let's say that we produce an SQL String which looks strikingly like this:

Dim strSQLUpdate
' If you're using SQL Server...
strSQLUpdate = "UPDATE tblOrders SET fldDateOrdered = '" & Date() & "' " & _
               "WHERE fldStatus = open ;"

' If you're using MS-Access...
strSQLUpdate = "UPDATE tblOrders SET fldDateOrdered = #" & Date() & "# " & _
               "WHERE fldStatus = open ;" 

The VBScripting engine interprets the Date() function as a value, formats it based on your Server/LCID settings, and then packages it all up as a *String* to send off to the database's Query Engine. Once the Query Engine recieves this SQL statement it goes about the job of Analyzing and Optimizing the query before passing it on the the Storage engine to actually file the information away in the database.

To see why this is a problem we simply need to understand that all dates are stored in the database as numbers. In order to be able to store a date as a number, the date has to be converted to something other than the standard calendar format. The numeric representation of dates is called a Julian, or Serial, date. To do this, the date is converted to an offset from a fixed point in time.

In the case of Microsoft Access, this offset is 30th-Dec-1899, and all dates are stored as the number of days since this date. Thus 7/7/93 is stored as 34157, meaning 34,157 days since 30th-Dec-1899. Negative numbers represent dates prior to 30th-Dec-1899.

Since adding 1 to a date represents 1 day or 24 hours, each hour is stored as .041666..., or 1/24 of a day. In Microsoft Access all times are stored as a fraction of a day. Each hour is 1/24 of a day, each minute 1/1440, each second 1/86400. So 3:00 is stored as .125 (or 1/8 of a day), and 16:00 is stored as 0.666..., (or 2/3 of a day). Conversely, 0.2 represents 4:48 hours (1/5 of a day), and so on.

Therefore we see that the following snippet produces a result of 28/02/1900 6:00:00 AM (assuming your LCID is set to display dates in dd-mm-yyyy format):

Response.Write CDate( CDbl(60.25) )

This is because 28th-Feb-1900 is 60 days added to 30-Dec-1899, and 06:00 AM is obviously a quarter (or .25) of the way through the day itself. The general point here is that the underlying value stored in the database is simply a DOUBLE.

Now that we know how a database physically stores a date (answer: as a DOUBLE), we're ready for Part 2, in which we'll look at how the Query Engine converts the SQL string containing the date (which is a string itself) into the proper format.

  • Read Part 2!


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article

  • internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info

    Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Whitepapers and eBooks

    Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
    IBM Solutions Brief: Go Green With IBM System xTM And Intel
    HP eBook: Simplifying SQL Server Management
    IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
    Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
    Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
    Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
    Intel PDF: Quad-Core Impacts More Than the Data Center
    Intel PDF: Virtualization Delivers Data Center Efficiency
    Go Parallel Article: PDC 2008 in Review
    Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
    Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
    Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
      PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
    Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
    Go Parallel Article: Q&A with a TBB Junkie
    IBM Whitepaper: Innovative Collaboration to Advance Your Business
    Internet.com eBook: Real Life Rails
    IBM eBook: The Pros and Cons of Outsourcing
    Internet.com eBook: Best Practices for Developing a Web Site
    IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
    Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
    IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
    Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
    HP eBook: Guide to Storage Networking
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES