Y
Y
Yuri Denisov2014-01-21 12:29:20
PHP
Yuri Denisov, 2014-01-21 12:29:20

What causes the DateTime error?

Good day to all!
There is such a piece

$month_now_first_day = new datetime('first day of 0 month midnight');
  $month_now_last_day = new datetime('last day of 0 month midnight');
  $month_now_first_day_in_time = strtotime($month_now_first_day->format('Y-m-d H:i:s'));
  $month_now_last_day_in_time = strtotime($month_now_last_day->format('Y-m-d H:i:s'));
  $month_now_text = strftime("%B", $month_now_first_day_in_time);

on one server it works fine, but on the second one php fails with
PHP error Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct() [ datetime.--construct ]: Failed to parse time string (first day of 0 month midnight) at position 10 (o): The timezone could not be found in the database' in /home/site/public_html/site/footer-index.php:64
Stack trace:
#0 /home/site/public_html/site/ footer-index.php(64): DateTime->__construct('first day of 0 ...')
#1 /home/site/public_html/site/index.php(28): include('/home/site/ ...')
#2 {main}
thrown in /home/site/public_html/site/footer-index.php on line 64

date_default_timezone_set('Asia/Novosibirsk'); inserted before script, plus htaccess lineSetEnv TZ UTC+06:00without it, 500 error at the server o_O
Can anyone help what is the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Q
Quber, 2014-01-21
@Quber

new datetime('first day of 0 month midnight');
What kind of format is this? It would probably be more correct like this:

new DateTime("2013-11-21 10:01:37");
new DateTime();

M
Mikhail Osher, 2014-01-21
@miraage

You are formatting the date incorrectly.
Try:

00:00 1st Jan
00:00 last day of Jan

For example,
date('Y-m-d H:i:s', strtotime('00:00 1st Jan'));
date('Y-m-d H:i:s', strtotime('00:00 last day of Jan'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question