9

I have one column as closed_date and data type is timestamp. I want to add the date in unix timestamp e.g. 1556801668. I don't know how to do that in Laravel.

3
  • What does this how to do that in Laravel mean? Commented May 2, 2019 at 13:05
  • Try using mutators Commented May 2, 2019 at 13:22
  • What have you tried? Where are you stuck? Commented May 2, 2019 at 13:48

3 Answers 3

7

use php strtotime() function to convert time.

Example

$time = '2019-01-01'

$timeStamp = strtotime($time);

// will output 1546300800
Sign up to request clarification or add additional context in comments.

2 Comments

how to do it in Laravel?
@Trupti it's a PHP function that you can use in any PHP scripts.
3

I you want to do this within the model, you can use castings:

protected $casts = [
    'closed_date' => 'timestamp',
];

Comments

0

If you have a Date string, for instance, you can create a Carbon object and store it directly into database.

Laravel will convert that object to the correct type for the database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.