Jason V. Castellano
Jason V. Castellano

Reputation: 316

How to update laravel date without updating time

Im trying to update the updated_at in laravel "2019-01-07 20:29:13" to "2019-15-18 20:29:13", but the problem is the time keeps updating also to "2019-15-18 00:00:00". How to update updated_at without touching the time ?

Upvotes: 1

Views: 1177

Answers (1)

Mayank Pandeyz
Mayank Pandeyz

Reputation: 26258

Instead of updating updated_at column you can add another column for this purpose and take it as date type only (recommended). But if you are not allowed to do this then you can try:

  1. Get the existing date and hold it in a variable and break it to get date and time separately or you can extract the time only.

  2. Combine your date with this time and make it datetime 'y-m-d H:i:s' using date() and strtotime() functions.

  3. Update the updated_at column with this new datetime value.

Upvotes: 3

Related Questions