Bikkebakke Posted April 24, 2010 Share Posted April 24, 2010 Hi again, Freaks! I stumbled upon a tiny-weeny problem I couldn't figure out myself, tried googling and searching for a while untill I decided to ask here, so: How do you count how many seconds/minutes/hours etc. it's been since a certain date/time? To be more specific, this is what I need to do: [*]Fetch a datetime from database (YYYY-MM-DD hh:mm:ss) [*]Count the minute difference between that value and current time [*]Add the minutes to the database value (matches current date/time except for seconds) -> This way I can store the minute difference in a variable and use it in a script AND update the datetime value in database without losing any seconds in that minute counting (since I only need to count the full minutes) And I would also need to echo how many seconds left till next full minute. Any help is appreciated. ~Bikkebakke Link to comment https://forums.phpfreaks.com/topic/199591-need-help-dealing-with-time-and-date/ Share on other sites More sharing options...
Bikkebakke Posted April 24, 2010 Author Share Posted April 24, 2010 Ah, finally figured it out. Incase anyone else faces the same problem: I decided to convert the date/time to minutes and store in a bigint field in database. To convert current time to minutes: floor(time()/60); To break it down: floor() <- rounds the value down time()/60 <- returns current time in seconds (seconds since 1970-something till present) and divides by 60 to convert the seconds to minutes. To echo seconds till the next full minute: echo date("s",60-time()); date() <- date function "s" <- tells the date function to display seconds 60-time() <- 60-current time (in seconds due to the "s"-part) Link to comment https://forums.phpfreaks.com/topic/199591-need-help-dealing-with-time-and-date/#findComment-1047673 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.