Jump to content

Converting the month from yyyy-mm-dd


Go to solution Solved by dadedidhodong,

Recommended Posts

I have a php program which accepts the input of the YYYY-MM-DD as the date format and stores it to the database. As soon as the user enters the date with YYYY-MM-DD format (e.g 1990-06-22) how can I convert the 06 (or the MM part) to June as in the 6th month of the year?

Link to comment
https://forums.phpfreaks.com/topic/281358-converting-the-month-from-yyyy-mm-dd/
Share on other sites

Is there a reason why you don't want to store the date as YYYY-MM-DD? That format is more useful for things like sorting.

 

When displaying the data, you could always use MySQL's date_format() function:

http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format

<?php
date_default_timezone_set('America/Vancouver');

$date = '2099-12-31';

echo date('F j, Y', strtotime($date));
?>
 

December 31, 2099

 

http://php.net/manual/en/function.date.php

 

http://php.net/manual/en/function.strtotime.php

Edited by Evan_McIntosh
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.