How to change date format

some1some1 ✭✭✭Member ✭✭✭

I have saved data in sqlite and when i retrieve it i get date in 'dd/MM/yyyy' format . I want to convert it to 'yyyy-dd-MM' format. How can i do that?

Best Answer

  • some1some1 ✭✭✭ ✭✭✭
    Accepted Answer

    i have Converted the data in WebService using .ToString().
    like date.ToString("yyyy/MM/dd hh:mm:ss tt") this.

    i just passed date from( in which ever format ) my project to web service and converted it there.

Answers

  • JarvanJarvan Xamurai Member, Xamarin Team Xamurai

    @some1

    i get date in 'dd/MM/yyyy' format. I want to convert it to 'yyyy-dd-MM' format.

    Do you mean get a string like 'yyyy-dd-MM', try the code.

    string s = DateTime.Now.ToString("yyyy-dd-MM");
    
  • some1some1 ✭✭✭ Member ✭✭✭

    @yelinzh my date is of type DateTime? . So ToString() cannot be used

  • JarvanJarvan Xamurai Member, Xamarin Team Xamurai

    my date is of type DateTime? . So ToString() cannot be used

    Can't be used?
    DateTime.ToString method converts the value of the current DateTime object to its equivalent string representation.

    See the tutorial:
    https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tostring?view=netframework-4.8

  • JohnHJohnH ✭✭✭✭✭ GBMember ✭✭✭✭✭

    @some1 said:
    @yelinzh my date is of type DateTime? . So ToString() cannot be used

    I think you are confusing how the DateTime is stored. It is stored as a DateTime, there is no formatting used when storing it as its type. When you display the DateTime, that is when you format it with ToString()

  • some1some1 ✭✭✭ Member ✭✭✭

    @yelinzh @JohnH i have stored DateTime? in 'dd/MM/yyyy' format in Sqlite. I want to pass that DateTime in url of WebService to update in one column of MSSql table.

  • some1some1 ✭✭✭ Member ✭✭✭

    @yelinzh if i convert DateTime? using ToString() and pass it in url . The webService is not detecting as valid DateTime.

  • JarvanJarvan Xamurai Member, Xamarin Team Xamurai

    Do you mean saving the DateTime vaule in sqlite in 'yyyy-dd-MM' format. According to the docs, there is no such format like 'yyyy-dd-MM'. See the Tutorial.

    If you want to show that, change the DateTime type to string and change the date_string manually.

  • JohnHJohnH ✭✭✭✭✭ GBMember ✭✭✭✭✭

    @some1 said:
    @yelinzh @JohnH i have stored DateTime? in 'dd/MM/yyyy' format in Sqlite

    No you haven't, you have probably saved it as a string.

  • some1some1 ✭✭✭ Member ✭✭✭

    @yelinzh @JohnH Thankyou so much for your reply . I have solved the issue. :)

  • some1some1 ✭✭✭ Member ✭✭✭
    Accepted Answer

    i have Converted the data in WebService using .ToString().
    like date.ToString("yyyy/MM/dd hh:mm:ss tt") this.

    i just passed date from( in which ever format ) my project to web service and converted it there.

Sign In or Register to comment.