How to convert MM/DD/YYYY to YYYY-MM-DD?

前端 未结 10 1795
忘了有多久
忘了有多久 2020-12-14 18:03

I have a jquery calendar that sets the input value to MM/DD/YYYY

How would I convert it so that my database column (date) can accept it correctly?

EDIT

10条回答
  •  爱一瞬间的悲伤
    2020-12-14 18:34

    You want to do this in PHP, right?

    1. Use Explode

      $christmas = "12/25/2010";
      $parts = explode('/',$christmas);
      $yyyy_mm_dd = $parts[2] . '-' . $parts[0] . '-' . $parts[1]
      
    2. Use strptime to parse it to a timestamp and then strftime to format it the way you want it.

提交回复
热议问题