Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Display in PHP

Status
Not open for further replies.

indiantown

Technical User
Apr 29, 2005
25
US
Hello All,

I need help to display date and time in my script, what I have tried whcih give me output Aug 12th, 2005 but I want to display Aug 12th, 2005 10:30 am (example)

The part of the code I am using is below:


/
/
/

$time_stamp = stripslashes($cats[time_stamp]);
$year = substr($time_stamp, 0, 4);
$month = substr($time_stamp, 4, 2);
$day = substr($time_stamp, 6, 2);
//$hour = substr($time_stamp, 8, 2);
//$min = substr($time_stamp, 10, 2);
$t = mktime(0, 0, 0, $month, $day, $year);

$date = date('M dS, Y ', $t);

Please suggest what and where I should make the changes to get the displayed format.

regards
 
I have the field in MYSQL database as time_stamp [timestamp(14)] and I am getting the format as 20050812202916.

Please suggest.
 
Based on the format you have given, here's the soln

Code:
    <?php

	$t = "20050812202916";
	$yr = substr($t,0,4);
	$mon = substr($t,4,2);
	$day = substr($t,6,2);
	$hour = substr($t,8,2);
	$min = substr($t,10,2);
	$sec = substr($t,12,2);
	$bday = mktime($hour,$min,0,$mon,$day,$yr);

    $dformatted = date('F dS, Y  g:i a',$bday);

    echo "Date with Time $dformatted."

    ?>

and the output is

Code:
Date with Time August 12th, 2005 8:29 pm.

-------Information is not knowledge-------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top