Very new to php so this might be a dumb question.
When a user selects a date and time on a previous webpage, the dateTimePurchased is held.
I am outputting it in the following statements:
echo "<tr><td>Date: ".$_SESSION['dateTimePurchased']."</td></tr>";
echo "<tr><td>Time: ".$_SESSION['dateTimePurchased']."</td></tr>";
Output for both is 2010-02-01 16:07:00
1. For the 1st line - Date:, how can I get the output to say Tuesday February 2, 2010
2. For the second line 4:07pm.
Can I mod just the lines I have to get the output correct?
Really appreciate any help.
date and time question
Moderator: General Moderators
Re: date and time question
PHP has a really convenient function called "strtotime" that takes just about any format of date and converts it to a unix timestamp (the date/time format PHP is most able to work with). Once you have the unix timestamp, you can use the "date" function to format it any way you like:
Code: Select all
$ts = strtotime($_SESSION['dateTimePurchased']);
$date = date('l F j, Y', $ts); // will be Tuesday February 2, 2010
$time = date('g:ia', $ts); // will be 4:07pmRe: date and time question
Thank you!