2

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();

2 Answers2

1

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');
STA
  • 30,729
  • 8
  • 45
  • 59
0

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.

Nolan H
  • 6,205
  • 1
  • 5
  • 19