0

the date stored in mysql is in Datetime format 'Y-m-d H:m:s' using laravel eloquent I want to convert Datetime format to date 'Y-m-d' the date stored in mysql table is 2016-11-29 17:23:56 and in the controller to convert I am using the below

$currentdate = Carbon::createFromFormat("Y-m-d H:m:s",$token->IssueDate)->format("Y-m-d");

the result I am getting is "2017-11-29" another example

Mysql record stored date is 2016-12-01 17:27:47 and the result I am getting is "2018-03-01"

Please help what am I missing here.

I have a constructor in the controller

public function  __construct()
{
  date_default_timezone_set("Asia/Kolkata");
}

which I don't think is a pronblem as after removing I am still getting the same result.

2 Answers 2

1

m is month. You want i for minutes (documentation):

$currentdate = Carbon::createFromFormat("Y-m-d H:i:s",$token->IssueDate)->format("Y-m-d");
Sign up to request clarification or add additional context in comments.

Comments

1

Change Y-m-d H:m:s to Y-m-d H:i:s (i refers to minute, not m). More on manual.

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.