-1

At the moment i'm attempting to try and save datetimes that are formatted in the american way (mm/dd/yy), now I have the jquery datepicker and I have updated that to format its date to be mm/dd/yy so they display correctly, but when I attempt to post, the ModelState throws an error stating that the date is not valid, for example 12/31/2014 is invalid, it is invalid in the en-gb way but not for US. How can I forward my modelstate to see this date (12/31/2014) to be valid?

I could save the datetime by coverting my mm/dd/yy to dd/mm/yy and when I want to pull out the date i can just convert again to mm/dd/yy but that seems quite wrong in my mind.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Canvas
  • 5,779
  • 9
  • 55
  • 98
  • 1
    Why do you want to _store_ it in an alternate format? Formatting should be something you worry about when outputting/displaying the data. – Ellesedil Jul 24 '14 at 14:20
  • That's why it was ISOed :D – Thomas Junk Jul 24 '14 at 14:23
  • So basically store the dates as normal format as they see in the database (2014-07-01 00:00:00) but when I display that, I convert to be american formatted? – Canvas Jul 24 '14 at 14:35
  • Yes. If you're trying to store dates in all sorts of different kinds of formats, you're going to be adding a lot of complexity for no real benefit. Let the DB take care of storing the data however it prefers, and worry about formatting only when you're using the data. – Ellesedil Jul 24 '14 at 15:19

1 Answers1

0

You need to use the correct conversion functions for MySQL to handle the date formats for whatever locales you are concerned about. See THE MYSQL REFERENCE PAGES for this. You probably will use str_to_date() as well as get_format() to save/retrieve the date value in whatever format you prefer

SlimsGhost
  • 2,849
  • 1
  • 10
  • 16