Jump to content

Converting Days Into Hours


unplugged_web
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...