0
votes

The Date format for USA is MM/DD/YYYY and British is DD/MM/YYYY.
The WinRT Tablet will set the Date Format base on the TimeZone when you First Turn on it for setting.

Let say I am setting my WinRT tablet to use British Date Format ( DD/MM/YYYY) and use this code to insert date into SQLite .


Class Order
      {
        [PrimaryKey, AutoIncrement]
        public int SId { get; set; }
        public int CustId { get; set; }     
        public string No { get; set; }        
        public string Customer { get; set; }
        public DateTime Order_Date { get; set; }

      }



   using (var db = new SQLite.SQLiteConnection(DBPath))
     {
        var newOrder = new Order()
        {
           CustId = g_intCustId,
           Customer = txtBlkCustomer.Text.Trim(),
           Order_Date = DateTime.Today   

        };

   db.Insert(newOrder);


1) What will be the Date format store by SQLite ? USA or British Date Format ?

2) How to set the date locale ( USA date or British date ) for SQLite database?

3) If above (2) is done, then the select statement (SQL-statement) base on date will base on the locale set?

Thanks

2

2 Answers

1
votes

I assume you're using .

According documentation, there is a DateTimeFormat parameter in SQLiteConnection´ parameters which will specify how DateTime is handled in database:

Ticks - Use the value of DateTime.Ticks.

ISO8601 - Use the ISO-8601 format. Uses the "yyyy-MM-dd HH:mm:ss.FFFFFFFK" format for UTC DateTime values and "yyyy-MM-dd HH:mm:ss.FFFFFFF" format for local DateTime values).

JulianDay - The interval of time in days and fractions of a day since January 1, 4713 BC.

UnixEpoch - The whole number of seconds since the Unix epoch (January 1, 1970).

InvariantCulture - Any culture-independent string value that the .NET Framework can interpret as a valid DateTime.

CurrentCulture - Any string value that the .NET Framework can interpret as a valid DateTime using the current culture.

Default is ISO8601. There is also a "custom" DateTimeFormatString and a DateTimeKind to specif UTF or local date times.

0
votes

You should never store localized dates in a database; this will break if the locale changes, and such strings do not sort correctly.

Either use the format yyyy-mm-dd (which is the only one supported by the internal SQLite date functions, and the only one where comparisons work correctly), or store timestamps as numbers.