Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

How to compare the different between two dateTime

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

How to compare the different between two dateTime

Postby bennos89 » Sat Sep 15, 2012 10:26 am

Hi,

I have datetime in my database and I want to check against the current datetime. I want to display the different between them. and If my database expiry. The php show not show the datetime.

$d1=new DateTime($c[0][0][4]);
$d2=new DateTime();
$diff=$d1->diff($d2);

However, I am getting weird number the sum wont tally.
echo $diff->format('%d-%m-%y %h:%i:%s');

What is the different between diff and sub
bennos89
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Sep 12, 2012 4:57 pm

Re: How to compare the different between two dateTime

Postby Marcus » Mon Sep 17, 2012 1:53 am

First if you are putting it in DB make it in UNIX time format is (1234454564) and for example you take current time also in UNIX and than compare it.

$time_in_db = //time in UNIX from DB;
$current = time();


if( $current < $time_in_db ){

//do something
}
else{
//report error
}
Marcus
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon Sep 17, 2012 1:35 am


Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron