More Group Sites
School Rankings
Jobless Net
Better Home
Enviro++


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest Search | Active Topics | Members | Log In | Register

How to insert datetime value in Australian date format into sql? Options · View
hong
Posted: Thursday, August 05, 2010 6:11:38 PM

Rank: Administration
Groups: Administration

Joined: 11/23/2008
Posts: 329
Points: 693
Location: Australia
If we insert a datetime string value like ‘8/27/2010 12:00:00 AM’ into a datetime field, it works. However, the Australian date format ‘27/8/2010 12:00:00 AM’ will lead to an invalid partial datetime format.

It’s found that Local ID (LCID) added to the connection string does change the database property Locale.
Code:
            SqlCeEngine engine = new SqlCeEngine(this.connectionString + ";Locale Identifier=3081");
            engine.CreateDatabase();


LCID values are assigned by Microsoft. For example:
English - United States, 1033
English - United Kingdom, 2057
English - Australia, 3081

However, database by default still accepts “yyyy-MM-dd” format. The datetime values in other formats inserted from code behind are converted to this format.
Code:
  string strInsertSql = string.Format("INSERT INTO CALENDAR (CALENDAR_DATE) " + "VALUES (‘{0}’)", aDay.Date.ToString("yyyy-MM-dd"));


The following the Australian date formats are also accepted.

Code:
INSERT INTO DAY VALUES ('15 AUG 2010')
INSERT INTO DAY VALUES ('15 AUG 10')


Other date formats supported
Code:
INSERT INTO DAY VALUES ('20100815')
INSERT INTO DAY VALUES ('100815')
INSERT INTO DAY VALUES ('08/15/2010')
INSERT INTO DAY VALUES ('08/15/10')
INSERT INTO DAY VALUES ('AUG 15 2010')
INSERT INTO DAY VALUES ('AUG 15, 2010')
INSERT INTO DAY VALUES ('AUG 15, 10')
INSERT INTO DAY VALUES ('AUGUST 15, 2010')


Related:
Help! SQL insert DateTime as float - Error converting data type varchar to float

How to get time from a datetime field in sql server CE

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime
Sponsor
Posted: Thursday, August 05, 2010 6:11:38 PM
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

ASPNET Theme created by Boskone (Dan Ferguson)
Powered by Yet Another Forum.net version 1.9.1.8 (NET v2.0) - 3/29/2008
Copyright © 2003-2008 Yet Another Forum.net. All rights reserved.
This page was generated in 0.292 seconds.