HCProfessionals Posted December 13, 2010 Share Posted December 13, 2010 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>"; } Quote Link to comment Share on other sites More sharing options...
Zurev Posted December 13, 2010 Share Posted December 13, 2010 You should be able to take the result, then make it a timestamp using strtotime, then use date format based on the chart found here: http://php.net/manual/en/function.date.php Quote Link to comment Share on other sites More sharing options...
HCProfessionals Posted December 13, 2010 Author Share Posted December 13, 2010 I'm just trying to figure out how i would do that with my existing code Quote Link to comment Share on other sites More sharing options...
Zurev Posted December 13, 2010 Share Posted December 13, 2010 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>"; } Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted December 13, 2010 Share Posted December 13, 2010 Or do it in the query: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format SELECT *, DATE_FORMAT(startrepeat, 'Your Format') FROM jos_jevents_repetition Quote Link to comment Share on other sites More sharing options...
HCProfessionals Posted December 13, 2010 Author Share Posted December 13, 2010 You guys are awesome! Quote Link to comment Share on other sites More sharing options...
Zurev Posted December 13, 2010 Share Posted December 13, 2010 Or do it in the query: http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_date-format SELECT *, DATE_FORMAT(startrepeat, 'Your Format') FROM jos_jevents_repetition Way to show me up! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.