Jump to content

Converting Days Into Hours


unplugged_web

Recommended Posts

I want to create my own time function rather then use the standard PHP Time function. The reason I want to do this is because I don't want days to be displayed but just hours - so 1 day becomes 24 hours. I've been told that the time is stored in DB using PHP time function and if you want to implement this I will need to write my own time function and then just create a function for 60 minutes = an hour, skip the rest of it so then it wont onvert to days. But I'm not sure how to do this.Thanks

Link to comment
Share on other sites

Dates are stored in databases either as a timestamp (amount of seconds that passed since 1970) or a date string, which can be something like 2009-11-12.You can't turn days into hours unless you have an interval from which you can count hours from. Maybe you want to count how many hours have passed since 1970.

Link to comment
Share on other sites

Dates are stored in databases either as a timestamp (amount of seconds that passed since 1970) or a date string, which can be something like 2009-11-12.You can't turn days into hours unless you have an interval from which you can count hours from. Maybe you want to count how many hours have passed since 1970.
I've got a site that counts down to events, but at the moment it's showing it as days, hours, minutes and seconds. I did want to have it only show hours, minutes and seconds. Is it not possible to convert days into blocks of 24 hours before they're entered into the database?
Link to comment
Share on other sites

I've got a site that counts down to events, but at the moment it's showing it as days, hours, minutes and seconds. I did want to have it only show hours, minutes and seconds. Is it not possible to convert days into blocks of 24 hours before they're entered into the database?
Extract the days from the date, multiply it by 24 and then sum it to the hours:
$hours = (idate("d",$my_timestamp) * 24) + idate("H",$my_timestamp);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...