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
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
Share on other sites

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.