locked
Insert string into MYSQL DB and show as date formatted RRS feed

  • Question

  • User539757411 posted

    Hi,

    I´m using C# and Mysql.

    Im inserting a date into database as a string with a mask like 03/30/2011 . 
    How do i show it by selecting dd/MM/yyyy ? By using String.format ?

    Is it better to convert to Mysql´s date format on inserting or to format on selecting ? 

    Friday, December 2, 2011 3:44 PM

Answers

  • User-718146471 posted

    Yes, in your formatting, you want to use dd/MM/yyyy for the formatting. Kind of like this:

    Myvarible.ToString("dd/MM/yyyy")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 3, 2011 9:50 AM

All replies

  • User-718146471 posted

    Generally speaking, it is always better to insert in a standard format and then format the output to how you'd like it to display. Keeping the standards helps in debugging and avoiding date related issues. In my experiences, MySQL databases work best if you use the UTC format but you can always use month/day/year. Depends what you are trying to do. If you are doing a lot of date comparisons, then UTC is best. If you are just tracking dates, then conventional month/day/year is fine.

    Friday, December 2, 2011 3:59 PM
  • User539757411 posted

    Thank you for that.

    But since, im inserting a date into database as a string with a mask like 03/30/2011. 
    How do i show it by selecting dd/MM/yyyy ? By using String.format ? 
    And how do i convert the string i am inserting as dd/MM/yyyy ? 

    Saturday, December 3, 2011 3:41 AM
  • User-718146471 posted

    Yes, in your formatting, you want to use dd/MM/yyyy for the formatting. Kind of like this:

    Myvarible.ToString("dd/MM/yyyy")

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, December 3, 2011 9:50 AM