PHP - Date_diff
I am a coldfusion developer starting out in php.
I am having trouble with dates. I just found out my server host is not supporting date_diff the host is running php5 can someone please help with an alternative I am trying to find out the difference between datetimes in seconds $interval = date_diff($fromdate, $todate); $secdiff = $interval->format('%s'); Thanks in advance Similar TutorialsI am trying to calculate the date and time difference between two timestamps. I am using this for an auction style website and I thought it was working fine until I woke up this morning and it said that there was only 1 hr left in auction when I actually started a 24 hour auction at like 7pm last night. //trying to find date diff accurately Code: [Select] $now = mktime(date("g"), date("i"), date("s"), date("m") , date("d"), date("Y")); $end = $timestamp; $start = new DateTime(); $start -> setTimestamp($end); $current = new DateTime(); $current -> setTimestamp($now); $interval = date_diff($current, $start, true); $days = $interval ->format('%d'); $hours = $interval ->format('%h'); $minutes = $interval ->format('%i'); $seconds = $interval ->format('%s'); This is how I created the timestamp to store in the database for auction. Code: [Select] //Creates timestamp for when auction ends using auction //length chosen. $timestamp = mktime(date("g"), date("i"), date("s"), date("m") , date("d")+$auction, date("Y")); Hi, so I am trying to get how many minutes and seconds are left from the datetime entry in the database and the current datetime, but I'm having issues... Here's my code: Code: [Select] $query = "SELECT RequestMadeDateTime FROM TempAwaitingClients WHERE PSOID = '2'"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); $RequestMadeDateTime = $row['RequestMadeDateTime']; $currentDateTime = date('Y-m-d H:i:s'); echo 'Request Made Date Time: ' . $RequestMadeDateTime . '<br />'; echo 'Current Date Time: ' . $currentDateTime . '<br />'; echo date_diff($RequestMadeDateTime, $currentDateTime); What I'm getting those is this, "Warning: date_diff() expects parameter 1 to be DateTime" ... Which I don't get because both variables are DateTime... What this parameter 'absolute' in DateTime::diff does? I have done some tests but i cant percept what is different when i set this parameter 'true'. Can you explain to me?! Thanks a lot. Best regards. |