Managing date formats differences between PHP and MySQL

后端 未结 7 1811
半阙折子戏
半阙折子戏 2020-12-09 13:53

I\'m writing my first PHP app that has to directly deal with dates, and thus to directly deal with the fact that PHP and MySQL have different date formats.

My questi

相关标签:
7条回答
  • 2020-12-09 14:35

    I would recommend you keep everything in mysql format until you need to display it to the user, then use strtotime() to get a unix timestamp and date() to format it.

    If you throw in some Hungarian Notation it's even harder to go wrong:

    $ymdDateAdded = date('Y-m-d');
    $timeDateAdded = strtotime($ymdDateAdded);
    $userDateadded = date('j F Y', $timeDateAdded);
    
    0 讨论(0)
提交回复
热议问题