I'm creating a new record with simple_form gem. There are 2 fields (start_date and end_date) which are for the date data.
Can someone help to understand how it is possible that the date saved is a day behind it was entered in the form?
#<Book:0x0000...
id: 16,
name: "My favorite book",
start_date: Thu, 30 Jun 2016 00:00:00 EEST +03:00,
end_date: Thu, 30 Jun 2016 00:00:00 EEST +03:00,
created_at: Thu, 30 Jun 2016 15:07:57 EEST +03:00,
updated_at: Thu, 30 Jun 2016 15:07:57 EEST +03:00>
Compare with:
INSERT INTO `books` (`name`, `start_date`, `end_date`, `created_at`, `updated_at`) VALUES ('My favorite book', '2016-06-29 21:00:00', '2016-06-29 21:00:00', '2016-06-30 12:07:57', '2016-06-30 12:07:57')
I'm trying to save June 30, but it stores June 29. How is it possible?
You're entering the date in EEST, and saving the date in UTC, so it will subtract 3 hours before saving it i.e. 2100 the previous day. If you convert the date back to EEST before you use it, you'll get the correct date.
Why it's doing this depends on your environment.