locked
[W8.1]How to get current date format settings in WinRt Store app RRS feed

  • Question

  • Dear all,

    I need to compare 2 date in my store application.

    Date1 is coming from a webservice remote database and Date2 is the Current Date.

    I have notice that when I convert the Date1( string) to a DateTime, the return date is not matching the correct system settings format while Date2 does.

    I am comapring date as below in order to know if it is matching current date :

    int result = DateTime.Compare(Convert.ToDateTime(item.ActionDate).Date, DateTime.Now.Date);

    I have read on different forum that MS do not use anymore system setting for handling date format but insted Globalization APi.

    How can do correctly that comparision by beeing sure both date are same format ?

    regards


    Friday, July 10, 2015 8:58 AM

Answers

  • Sorry mate, didn't notice you were still working on this one.

    You need to specify a culture when you do the todatetime.

    Like:

                string sdate = "2015-10-07 02:00:00";
                DateTime dat = Convert.ToDateTime(sdate, CultureInfo.InvariantCulture);
                Debug.WriteLine("{0:dd-MMM-YYYY}", dat);

    Which gives me 7 October.

    so like:

    Convert.ToDateTime(item.ActionDate, CultureInfo.InvariantCulture)


    Monday, July 13, 2015 5:22 PM

All replies

  • To what format the Date1 gets convert, can you paste that here

    http://developer.nokia.com/community/wiki/Using_Crypto%2B%2B_library_with_Windows_Phone_8

    Friday, July 10, 2015 9:04 AM
  • First check that server time is Universal time or not , if not ask your server side people to get Universal time and convert it to local time at your client side then compare that date and DateTime.Now.Date.
    Friday, July 10, 2015 9:07 AM
  • The date itself isn't in a format, you format it to view it.

    When you loo at the ActionDate ( presumably this is a string ? ) what does it look like?

    Maybe it isn't actually the same as now.

    You could perhaps use a specific culture on your convert.

    https://msdn.microsoft.com/en-us/library/windows/apps/9xk1h71t(v=vs.105).aspx

    Convert.ToDateTime(item.ActionDate, Culture.WhateverItIs ).


    Friday, July 10, 2015 9:23 AM
  • Hello

    Based on the follwing conversion I need to do :

    int result = DateTime.Compare(Convert.ToDateTime(item.ActionDate).Date, DateTime.Now.Date);

    Item.ActionDate is a string date field in SQite database saved as : 2015-10-07 02:00:00

    Convert.ToDateTime(item.ActionDate) return : 10/7/2015 2:00:00 AM
    DateTime.Now returns : 7/10/2015 11:39:32 AM

    As you can see, format is different here , first date understand October and second Jully, but both date are in fact Jully

    In my WinRT table settings are as follow :

    - REGION set to France
    - ShortDate format : M/d/yyyy
    -Long Date format : dddd,MMMM,d,yyyy

    So based on this why the Item.ActionDate is getting all time US settings which I don't have set in my device ? How to solve it to reflect my datetime setting of my device

    regards

    Friday, July 10, 2015 9:45 AM
  • any advise on this ?
    Monday, July 13, 2015 2:09 PM
  • Sorry mate, didn't notice you were still working on this one.

    You need to specify a culture when you do the todatetime.

    Like:

                string sdate = "2015-10-07 02:00:00";
                DateTime dat = Convert.ToDateTime(sdate, CultureInfo.InvariantCulture);
                Debug.WriteLine("{0:dd-MMM-YYYY}", dat);

    Which gives me 7 October.

    so like:

    Convert.ToDateTime(item.ActionDate, CultureInfo.InvariantCulture)


    Monday, July 13, 2015 5:22 PM