1

The Unix Time Stamp generated by my MKTIME is not generating correctly

(European format)

Date Submitted: 15/02/2014 19:00

Unix Code: 1392508800

This returned date is: 16/02/2014 00:00:00 Code it should of returned is: 1392490800

Code Used After form is submitted values are captured and assigned...

if ($_POST['Callbacl']){

    $CID=$_POST['ID'];
    $Notes = $_POST['callbacknotes'];

    $Time_H = $_POST['Time_Hour'];
    $Time_M = $_POST['Time_Minute'];
    $Date_Day = $_POST['Date_Day'];
    $Date_Month = $_POST['Date_Month'];
    $Date_Year = $_POST['Date_Year'];

    $Appt = mktime($Time_H, $Time_M,00, $Date_Month, $Date_Day, $Date_Year);
    echo $Appt . "<br>";
    die;
}

Post values

     Array ( 
    [ID] => 1 
    [Time_Hour] => 19 
    [Time_Minute] => 00 
    [Date_Month] => 02 
    [Date_Day] => 15 
    [Date_Year] => 2014 
    [callbacknotes] => 
    [Callback] => Call Back 
    )
DataCure
  • 425
  • 2
  • 15
  • try like this to set a date format to unix: `$yourdate->format('U');` – Awlad Liton Jan 22 '14 at 03:54
  • 1
    Simplify your sample. Get all time related values, and post only them, result `mktime` returns and why you think it's incorrect. How you get the values doesn't matter. – MarcinJuraszek Jan 22 '14 at 03:56
  • Can you show us the output of: print_r($_POST) ? – Milan Babuškov Jan 22 '14 at 03:58
  • Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [datetime.--construct]: Failed to parse time string (02/15/2014 19:00,00) at position 17 (0): Unexpected character' in /home/a5556232/public_html/clients_search_client.php:57 Stack trace: #0 /home/a5556232/public_html/clients_search_client.php(57): DateTime->__construct('02/15/2014 19:0...') #1 {main} thrown in /home/a5556232/public_html/clients_search_client.php on line 57 – DataCure Jan 22 '14 at 04:04
  • Milan Babyskov: Array ( [ID] => 1 [Time_Hour] => 19 [Time_Minute] => 00 [Date_Month] => 02 [Date_Day] => 15 [Date_Year] => 2014 [callbacknotes] => [Callback] => Call Back ) – DataCure Jan 22 '14 at 04:07
  • Set your default timezone `date_default_timezone_set('America/Los_Angeles');` this may help you. – Kaushik Jan 22 '14 at 05:03

1 Answers1

1

I suppose to your time zone in php.ini is not your preferred one. Try to set a proper time zone in php.ini or to add the following code at the beginning of your block.

date_default_timezone_set('your time zone');

There is the list of supported time zones in PHP:

http://www.php.net/manual/en/timezones.php

Marko Novakovic
  • 470
  • 2
  • 10
  • Turns out that is the correct answer sir; hats off to you I just cant seem to understand why a timezone would affect the count of seconds between 00:00:00 01/01/1970 and the date supplied (Shouldnt the value be the same no matter where in the world you live) since every one has 60 seconds in 1 minute and 60 minutes in 1 hr etc etc Any how thank you – DataCure Jan 22 '14 at 15:58
  • PHP mktime returns the difference between 00:00:00 01/01/1970 UTC and provided date in your chosen timezone. – Marko Novakovic Jan 22 '14 at 16:24