I want to update ends_at column of subscriptions table. When i use
Carbon::now()
It update perfectly but when is use
Carbon::now()->addCenturies(5);
I am face error
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2520-08-07 11:39:13' for column 'ends_at' at row 1 (SQL: update `subscriptions` set `ends_at` = 2520-08-07 11:39:13, `subscriptions`.`updated_at` = 2020-08-07 11:39:13 where `id` = 1)
i want one subscription for life time due to this i think add centuries. kinldy tell me solution my controller code is
$subscription = $user->newSubscription('default', $plan->plan_id)->create($request->paymentMethod, [ 'email' => $user->email ]);
$subscription->ends_at = Carbon::now()->addCenturies(5);
$subscription->save();
The TIMESTAMP data type is used for values that contain both date and time parts. TIMESTAMP has a range of 1970-01-01 00:00:01 UTC to 2038-01-19 03:14:07 UTC. Your given year is 2520 and your MySQL can handle year as max 2038.
Change the migration timestamp to dataTime format as :
$table->timestamp('ends_at');
to
$table->dateTime('ends_at');
It looks like ends_at is meant to be managed for you by Laravel Cashier, not something you modify manually. Reviewing the source code, it is only updated based on other values, not any parameters. It also is not used to set any parameters in Stripe API requests. The cancel_at parameter would seem to most likely mapping.
If you wish to set cancel_at, it takes an epoch timestamp (in seconds). As #sta mentioned above, this has a maximum value of 2147483647, representing a time in 2038.
Note also that Subscriptions will by default continue in perpetuity, so it is not necessary to set an "end date" 5 centuries from now.
Related
I am trying to create a measure that will return a value for the number of issued receipts in the year 2020:
CALCULATE(SUM(Receipts[issued]), FILTER(Receipts, Receipts[Year] = 2020))
However, the measure keeps returning blank, even as a calculated column.
I've also tried
CALCULATE(SUM(Receipts[issued]), FILTER(Receipts, Receipts[Year].Year = 2020))
But that is returning an error saying the syntax for "Year" is incorrect.
The Year column is of datatype Date and is linked to a dimDate table on the Date column.
I am trying to retrieve the value 440,000. What am I doing wrong?
Try this.
CALCULATE(SUM(Receipts[issued]), YEAR(Receipts[Year]) = 2020)
So I have a table to log profile followers every 10 minutes to keep a record of the increase/decrease.
However after the current day I only need to keep the last record of that day. Is there a simple way in Laravel to delete all records a part from the last one recorded every day.
I've tried searching and searching but comes up with nothing and feel like I'm going to create something overly complicated to accomplish this.
You'd need a query like this.
DELETE
FROM logs
WHERE id IN (
SELECT id
FROM logs
WHERE created_at BETWEEN 2022-02-28 00:00:00 AND 2022-02-28 23:59:59
ORDER BY created_at DESC
OFFSET 1
)
Assuming you have a date variable, you could make the query like this using the whereDate method:
$date = '2022-02-28'; // Y-m-d format. This is important.
DB::table('logs')
->whereIn('id', function ($sub) use ($date) {
$sub->select('id')
->from('logs')
->whereDate('created_at', $date)
->orderByDesc('created_at')
->offset(1);
})
->delete();
I am making api's in laravel and getting 2021-01-30T10:30:17.704 05:30 from $request->followup and i have column in database named followup having datetime datatype. But it's giving me following error.
Carbon\Exceptions\InvalidFormatException: Could not parse '2021-01-30T10:30:17.704 05:30': DateTime::__construct(): Failed to parse time string (2021-01-30T10:30:17.704 05:30) at position 24 (0): Double time specification in file D:\xampp2\htdocs\synocrm-baid\rest-apis\vendor\nesbot\carbon\src\Carbon\Traits\Creator.php on line 188
I tried to change format like
$followupDate = date('Y-m-d h:i:s A',strtotime($request->followup));
My modal having
#property Carbon|null $followup
$request->followup is appending datetime with datetime
Original Value: 2021-01-30T10:30:17.704 05:30
Datetime: 2021-01-30T10:30:17.704
Time: 05:30
As we can see, there is two Time (05:30 and 10:30:17), because of which the strtotime() cannot convert the value.
In order to fix the problem,
Send the value as time time only (2021-01-30T10:30:17.704) instead of two times Time attribute
If you have no control over request value, you can retrieve only date value like:
$dateValue = explode(' ', $request->followup)[0];
$followupDate = date('Y-m-d h:i:s A',strtotime($dateValue));
Or Using Carbon
$followupDate = Carbon::parse($dateValue);
I would not recommend option 2 because it creates problems and confusion for other devs.
2021-01-30T10:30:17.704 05:30
It does not seem to valid timestamp. For parsing, it should be the valid timestamp or date.
I'm using Laravel 5.4 and Carbon to find dates that are exactly one day and three days prior to a laravel job (to the hour) to send notifications. So for example if the date was 2019-03-10 18:00:03 or 2019-03-10 18:15:34, I'd like to send a notification tomorrow at 2019-03-07 18:00:00 and another at 2019-03-09 18:00:00. I'd like to do this in an eloquent query, but not really sure how to "lazy match" by day and hour. If I have an Appointment model with a start_date timestamp, I know I can do exact matches by day or date, but I want to find matches that disregard the hours/seconds. I was considering something along these lines:
$oneDayAppointments = Appointment::whereDay(
'start_date',
Carbon::now()->addDay()->day
)->get();
...would get me any appointments where the start_date is a day from now. Now how would I hone it to the day and hour. If I were to just use a where clause:
$oneDayAppointments = Appointment::where(
'start_date',
Carbon::now()->addHours(24)
)->get();
...I could get exact matches, but only if the minutes/seconds were a match as well. Thanks!
Working on my comment above, this should do it
$tomorrowStart = Carbon::createFromFormat('Y-m-d H:i:s', Carbon::now()->addDay()->format('Y-m-d H:00:00'));
$tomorrowEnd = $tomorrowStart->copy()->addHour()->subSecond();
//whereBetween('start_date', [$tomorrowStart, $tomorrowEnd])
https://laravel.com/docs/5.8/queries
I want to create validation rule to validate incoming date.
Format I want to validate is Y-m-d H:i:s. Here's my body request which I am validating:
{ "date":"2015.10.5 10:30:10" }
And here's my validation rule:
'date' => 'required|date_format:"Y.m.d H:i:s"',
And it returns:
{"date":["The date does not match the format Y.m.d H:i:s."]}
If you want to be able to pass the day without a leading zero, then for the day part of your datetime you need to use j instead of d.
'date' => 'required|date_format:"Y.m.j H:i:s"',
That will work for the example you have above.
If you are going to always have a leading zero in your day (so, 05 instead of just 5, then the date format you already have will work.