Re: Help with adding time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 6 dec 2016 kl. 09:01 skrev Danny <mynixmail@xxxxxxxxx>:
> 
> Hi guys,
> 
> I am trying to add 30 minutes to a Unix time stamp. Currenly the seconds are
> increased but not the minutes.
> 
> The UNIX timestamp is echoed into a file by a BASH script for later use.
> 
> Here is my code:
> ####################################################################################
> <?php
> 	$time_now = time() ;
> 
> 	$BASH_file = fopen ( "/usr/local/bin/scripts/txt/time.txt", "r" ) ;
> 	$BASH_value = fread ( $time_file, "10" ) ;
> 
> 	$current_time = ( date ( 'Y-m-d H:m:s', $time_now ) ) ;
> 	$endtime =  ( date ( 'Y-m-d H:m:s', $BASH_value ) ) ;
> 	
> 	$target_time = date ( 'Y-m-d H:m:s', strtotime ( "+30 minutes", $BASH_value ) ) ;
> 	
> 	print ( $target_time."\n" ) ;
> 
>        if ( $current_time >= $target_time )
>          {
>            print ( "Time is greater\n" ) ;
>          }
>        else
>          {
>            print ( "Time is less\n" ) ;
>          }
> 	
> 	fclose ( $time_file ) ;
> 	
> ?>
> ###################################################################################
> 
> Any pointers?
> 
> Thank you
> 
> Danny
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

Hi Danny!

That’s because you are formatting your dates wrong. Have a look here: http://php.net/manual/en/function.date.php:

i - Minutes with leading zeros

The date format should be: 'Y-m-d H:i:s'

/frank
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux