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!

Working with date and times

Status
Not open for further replies.

GWHicks

Programmer
Dec 11, 2002
39
US
I am trying to write a script that pulls information from our MySQL database on employees that are currently clocked in. I am pulling everything fine, but am trying to clean up the output by breaking up the date and time from the clock in into seperate fields.
Below is the array that I use to get each employee, then starting with the $datein= line I try to break up the $starttime value into hours, minutes, month, etc. However when I display those "broken down" values in my table it shows me December 31, 1969 and some hour display (current GMT?) If I take out the $starttime from my $datein= line it defaults to current time and displays what I want.
How do I get the time returned from the database to show in this broken down format?
Thanks for any tips or pointers, just getting started teaching myself PHP so I could be way off the mark here. Feel free to give a slight slap upside the head to point me in a better direction!
Greg

MY CODE:
while ($newArray = mysql_fetch_array($clockedin)) {
// give a name to the fields
$empnum = $newArray['Employee_Number'];
$starttime = $newArray['date_time'];
$lastname = $newArray['Last_Name'];
$firstname = $newArray['First_Name'];
$datein = getdate($starttime);
$monthin = $datein[month];
$dayin = $datein[mday];
$yearin = $datein[year];
$hourin = $datein[hours];
$minutein = $datein[minutes];


Greg Hicks
VB.Net (Newbie) Programmer
 
getdate() takes as its input an integer time tick number, not a date/time string. However, PHP provides the function strtotime() ( which will take as its input a date/time string (and it works well with MySQL's date/time format), and returns the integer time tick. You can then pass that value to getdate():

$datein = getdate(strtotime($starttime));


Want the best answers? Ask the best questions: TANSTAAFL!!
 
That was it, thanks. Now hopefully I will remember that when I am working through future issues with dates and times!
Greg

Greg Hicks
VB.Net (Newbie) Programmer
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top