In my Laravel application I have a form in which you put the date to capture the date of an expense. This field is a MySQL DATE field so the format is yyyy-mm-dd.
The timezone in my application is set within config/app.php
like so.
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'Europe/London',
Fairly recently in Britain we entered into British Summer Time (as we do every year) and this raises my actual question.
A user used a date picker to select 2022-04-04 and this was entered into the database as 2022-04-04.
The issue is with the return value from an accessor.
/**
* Force date format.
*
* @param [type] $value
* @return void
*/
public function getDateAttribute($value)
{
return Carbon::parse($value)->format('d M Y');
}
(Note that the date field has also been cast to a Carbon instance.)
This comes back as 03 Apr 2022, and if you add Y-m-d H:i:s
it comes back as 2022-04-03 11:00
Given the picture above can I assume that Europe/London
is equivalent to GMT
?
Update
I failed to mention that I'm using vue-datepicker
so when I select a date it looks like this:
I then pass this through moment.js like so.
"date": moment(this.date),
Which sends through as follows
Update 2
I send the date to my backend via an axios request and I format it with moment.js like so:
axios.post('/api/expenses/personal', {
"date": moment(new Date(this.date)).format('YYYY-MM-DD'),
"business_reason": this.business_reason,
"total_before_vat": this.total_before_vat,
"category": this.category,
"centre_cost_centre_id": this.centre_cost_centre_id,
"is_foreign_expense": this.is_foreign_expense,
"total_before_conversion": this.total_before_conversion,
"conversion_rate": this.conversion_rate,
"currency": this.currency,
"has_vat": this.has_vat,
"vat_claimed": this.vat_claimed,
"total": this.calculatedTotal,
"expense_group_id": this.$route.params.expense_group_id
})