php - time() and date() problems after time change (DST - standard) -


in php output html option list containing dates next 14 days.

these appointments @ 18 o'clock:

$today_day = date('d'); $today_month = date('m'); $today_year = date('y'); $date_entry = mktime(18, 00, 00, $today_month, $today_day, $today_year); $optionsstr = '<select name="date">'; ($d = 1; $d < 14; $d++) {     $date_entry_temp = $date_entry+86400*$d;     $optionsstr .= '<option value="'.$date_entry_temp.'">'.date('d.m.y', $date_entry_temp).'</option>'; } $optionsstr .= '</select>'; echo $optionsstr; 

the user can choose 1 of these dates , submit form. chosen timestamp inserted database.

so have entries in database.

on page there list of current appointments:

mysql_query("select id, name appointments date_time = ".time()); 

so @ 18 o'clock there should output there entries in database day. works until time changes dst standard time or vice versa. then, indeed, wrong:

the appointments shown 1 hour late or respectively.

how can solve problem?

mktime() creates unix timestamp. unix time stamp number of seconds january 1, 1970, 00:00:00 gmt +0000. (greenwich time)

when set timezone "europe/berlin", timezone either gmt+0100 (in winter) or gmt+0200 (in summer). means greenwich time of appointments changes 1 hour when have dst. means time between first appointment before change , next appointment after change not 24 hours, 23 or 25. however, generate appointments adding 86400 seconds = 24 hours.

you can use datetime object , add() method instead. takes dst changes account.

// create new date object todays date $date = new datetime(); // set time 18:00 $date->settime(18,0,0); $optionsstr = '<select name="date">'; ($i = 0; $i < 14; $i++) {     // add 1 day     $date->add(new dateinterval('p1d'));     $optionsstr .= '<option value="'.$date->format('u').'">'.$date->format('d.m.y').'</option>'; } $optionsstr .= '</select>'; echo $optionsstr; 

see http://www.php.net/manual/en/datetime.add.php more information.


Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -