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>"; } Link to comment https://forums.phpfreaks.com/topic/221527-php-format-dattime/ 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 Link to comment https://forums.phpfreaks.com/topic/221527-php-format-dattime/#findComment-1146734 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 Link to comment https://forums.phpfreaks.com/topic/221527-php-format-dattime/#findComment-1146749 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>"; } Link to comment https://forums.phpfreaks.com/topic/221527-php-format-dattime/#findComment-1146796 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 Link to comment https://forums.phpfreaks.com/topic/221527-php-format-dattime/#findComment-1146803 Share on other sites More sharing options...
HCProfessionals Posted December 13, 2010 Author Share Posted December 13, 2010 You guys are awesome! Link to comment https://forums.phpfreaks.com/topic/221527-php-format-dattime/#findComment-1146840 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! Link to comment https://forums.phpfreaks.com/topic/221527-php-format-dattime/#findComment-1146852 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.