Jump to content

PHP - Format Dattime


HCProfessionals

Recommended Posts

I have my date set in my database as: 2010-12-13 08:00:00

 

What I would like to do is use PHP to format the date when pulled out the database to say: December 13, 2010. I really do not need the time if we can toss that. I wish it was as easy as changing info in the database directly, but with teh way everything has been programmed, it would be too much work. Here is an example:

 

$data = mysql_query("SELECT * FROM jos_jevents_repetition") or die(mysql_error('Error connecting to the database'));

while ($row = mysql_fetch_array($data)) {
   echo
   "<label for='name'>Dates</label>",
   "<select type='text' name='name'>",
      "<option value=''>Please Select A Date </option>",
      "<option value='".$row['startrepeat']."'>".$row['startrepeat']." </option>",
   "</select>";
}

Link to comment
https://forums.phpfreaks.com/topic/221527-php-format-dattime/
Share on other sites

Well if $row['startrepeat'] is your 2010-12-13 08:00:00 timestamp, then do something like:


$data = mysql_query("SELECT * FROM jos_jevents_repetition") or die(mysql_error('Error connecting to the database'));

while ($row = mysql_fetch_array($data)) {
$dateStamp = strtotime($row['startrepeat']);
$dateFormatted = date("F j, Y", $dateStamp);

   echo
   "<label for='name'>Dates</label>",
   "<select type='text' name='name'>",
      "<option value=''>Please Select A Date </option>",
      "<option value='".$dateFormatted."'>".$dateFormatted." </option>",
   "</select>";
}

Link to comment
https://forums.phpfreaks.com/topic/221527-php-format-dattime/#findComment-1146796
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.