Jump to content

Problem Campare Timestamp with date inside in a array....


angelicaescobar

Recommended Posts

Hello !!  I am new programing PHP, and slow to learn... please i need help.... I hope you can. this is my case:

 

I have a date that is in an array in this posistion:

 

$bookings[$i-1][date("d.m.Y",$timestampOfMonday+($x*86400))]["daterequest"]

 

and i want to compare it with the actual time, and if it is bigger than one hour appears one message......  but it doesnt work      :-\

 

I have the idea to use the time() like this:

 

time($bookings[$i-1][date("d.m.Y",$timestampOfMonday+($x*86400))]["daterequest"]) 

 

but the time that geve me back is the system time, not the time that is storage inside the array...  ???

 

then i have this idea.. but still do not works.... :-[

 

$date1 = $bookings[$i-1][date("d.m.Y",$timestampOfMonday+($x*86400))]["daterequest"]; 

        $date2 = time();   

              $dateArr  = explode(".",$date1); 

              $date1Int = mktime(0,0,0,$dateArr[1],$dateArr[2],$dateArr[0]) ;

            $dif = $date2-$date1/60/60/60;               

             

                if (isset($bookings[$i-1][date("d.m.Y",$timestampOfMonday+($x*86400))])){

                 

                  //IF There is a booking and the time of request is smaller than 1 hour, con make changes

                  if  $dif > 3600{ 

                    echo "...make something..."

                  }

                  //IF There is a booking and the time of request is bigger than 1 hour, NO changes  can made

                    else {

                    echo ":....Say other thing.."

      }

                } 

 

 

 

Where is the error??  Why i can compare the dates?? Why if i use the time() it gives me back other time?? 

 

THANKS FOR YOUR HELP!!!

Hi,

 

First of all time() function returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT). It does not take any input argument. Even if you supply, it'll return the current time.

 

It seems you are using a 3D array $bookings, which holds the time. Anyways, it doesn't matter.

 

Instead of using time() use date(). The prototype of date() is:

 

string date ( string $format [, int $timestamp ] )

 

The timestamp is optional, its the int value which will be converted into date/time according to the format $format.

 

And regarding your 3rd example: plz check the date format in array.

 

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.