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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timestamp problem

Status
Not open for further replies.

krappleby025

Programmer
Joined
Sep 6, 2001
Messages
347
Location
NL
I am pulling data from a database timestamp field, and trying to generate a formated date form it. however i have a problem...

The coding im using is

$newdate = date("d/m/Y",$signdate);
(signdate being the timestamp field)

the var $newdate, produces 18/01/2038

however...

the timestamp states

20031026134827

which as you can see should read 26/10/2003

so why is it instead producing 18/01/2038.

any ideas

thanks
 
IAW date() takes two inputs, one required, one optional. The first input parameter is required and is the format string for the date you wish the function to produce. The second optional one is an integer which enumerates, in seconds, the time since the beginning of the Current Unix Epoch (1970-01-01 00:00:00).

You are handing the function a string that looks like an integer, so date() calculates the date wrong.

The PHP function strtotime() ( can take a date string and produce the CUE timetick.

Combining the two, you can do something like:

$newdate = date("d/m/Y",strtotime($signdate));

and get the right date.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
thanks, i will look at the sites, but with your example im now getting
31/12/1969

way out lol

thanks
 
It sounds to me like strtotime() doesn't understand your date string format. You might consider performing the format on the MySQL side:

SELECT date_format(dt, '%d/%m/%Y') from foo;

(

or do it on the PHP side without using strtotime:

<?php
$timestamp = '20031026134827';
$timestamp = preg_replace ('/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/', '$3/$2/$1', $timestamp);
print $timestamp;
?>

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top