Date on e-mail sent is 1 day earlier.
JohnNoc - October 29, 2007 - 08:21
| Project: | Webform |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Description
The date from the date field on the e-mail message I receive is 1 day earlier than the date the user chose and submitted in the form.
Eg. User chooses February 20 from the drop-down list, year 2008. Sends the form.
E-mail received- Submitted values are: Date: February 19, 2008
The date is correct on the table at http://example.com/node/nid/results/table though.

#1
I have the same problem, has anyone pinpointed or created a patch for it?
Database and 'results' tab of the webform show the correct date, only the email sent is off by one day.
This is very disturbing as we use it for input on date of birth.
#2
and we use this for restaurant booking....so it's a MAJOR problem for us :-(
#3
I've been searching through the code but it all seems fine ... where does this come from? Anyone from the dev-team of this module know why?
#4
Same here, also for a restaurant booking.
Is there a patch available yet??
#5
Any updates yet? Please let us know :)
#6
Is the problem that the function theme_webform_mail_date in components > date.inc has a format_date call that needs to be rewritten from this...
function theme_webform_mail_date($data, $component) {$output = $component['name'] .":";
if ($data['month'] && $data['day']) {
$timestamp = strtotime($data['month'] ."/". $data['day'] ."/". $data['year']);
$output .= " ". format_date($timestamp, "custom", 'F j, Y', 0);
}
return $output;
}
to this ...
function theme_webform_mail_date($data, $component) {$output = $component['name'] .":";
if ($data['month'] && $data['day']) {
$timestamp = strtotime($data['month'] ."/". $data['day'] ."/". $data['year']);
$output .= " ". format_date($timestamp, "custom", 'F j, Y', NULL);
}
return $output;
}
I believe from the API that format_date is expecting the last parameter to be a timestamp offset in seconds. If omitted, the user's time zone is used. In this case 0 would be interpreted differently from NULL. Seemed to work for me.
#7
Didn't work for me ...
#8
Same here, didn't work for me either....
I really need this to work correctly. Any updates so far?
#9
Hmm, very unclear why this should be happening. The date is stored in the database as the three separate components (day, month, year) which you can see being dropped in on line 4 of the theme_webform_mail_date function...
function theme_webform_mail_date($data, $component) {$output = $component['name'] .":";
if ($data['month'] && $data['day']) {
$timestamp = strtotime($data['month'] ."/". $data['day'] ."/". $data['year']);
$output .= " ". format_date($timestamp, "custom", 'F j, Y', 0);
}
return $output;
}
It's converted to a UNIX timestamp and then run through format_date to make it a nice readable string for the email. Couldn't be more simple.
I think the problem is something to do with the timezone in the format_date call. strtotime($data['month'] ."/". $data['day'] ."/". $data['year']) creates the timestamp at midnight (00:00 on month/day/year). If 0 is used for a timezone setting, then the timestamp will (I think) be GMT. If your timezone is forward of GMT, then the format_date call would work with a time behind your timezone, giving you the date for the previous day. Does that make sense...?
Hard to see what's going wrong without it being something related to the timezone setting, here and in the site settings. 0 is an integer/numeric and not the same as NULL.
Do you have a 'default value' set for your date component(s)? Does that make a difference?
The webform date component has a timezone option - that doesn't seem to be picked up in the theme_webform_mail_date function at the moment, so can't be anything to do with that.
Do you have user-configurable timezones in your Drupal installation? Is your site timezone set correctly?
I still think it should be
$output .= " ". format_date($timestamp, "custom", 'F j, Y', NULL);#10
Has anybody noticed that in the month/day selection pop ups to first entry is "month" and "day", respectively? When selected, it results in an invalid date error, but still not looking good to the untrainned eye.
Changing the output line as suggested in post 9 did the job here...
#11
In the end it proved to be both for me ...
My site was set in GMT (instead of CET) _and_ the line had to be adjusted from 0 to NULL
tnx
#12
Changing 0 to NULL made no difference for me, it's still a day off.
#13
#14
#15
I suspect the output from strtotime() is affected by the timezone as PHP knows it, set on the server.
The format_date() function then applies Drupal-specific timezone on a timestamp that may not be GMT.
PHP here is set GMT+1000 with Drupal set the same. I think this caused date in email to be 20 hours behind.
Attached patch which works here. I'd be interested to know if this works for others in various timezones.
It's not great code, though best solution I could find without requiring PHP 5.1+
#16
Brendan's patch fixes my issue, which is no surprise considering we're working on the same project.
#17
Can we get some more testers on the latest patch?
#18
This code patch is also working ok for me.
Thank you
#19
Works for me too.
#20
Thanks guys.
#21
Didn't have any affect for me I'm afraid. Still the same problem of being 1 day behind.
#22
Got the same error in Webform 2 beta 3, with "NULL" instead of "0" it worked for me...
regards pebosi
#23
Thanks everyone. I'm assuming that this fixes most sites, or at the very worst, doesn't cause harm to existing sites. Committed.
Anyone feeling ambitious can clean it up, but this has been going on so long I'd prefer just to leave it be and not touch it :)
#24
Automatically closed -- issue fixed for two weeks with no activity.