Javad Yousefi
Javad Yousefi

Reputation: 2300

convert string to date type in php

I have 3 variable $day , $month and $year and I want to create a date variable with these 3 variables in this fromat : yyyy-mm-dd in php.

$year variable is a persian year for example $year= 1390

this code works properly but not for persian date :

date("d-m-Y", mktime(0, 0, 0, $fMonth, $fDay, $fYear));

How I can do it ?

Upvotes: 2

Views: 3410

Answers (3)

Pezhvak IMV
Pezhvak IMV

Reputation:

http://ir.php.net/manual/en/function.mktime.php

Usage:

$myTime = date("d/m/Y", mktime(0, 0, 0, $month, $day, $year));

Upvotes: 4

Sinan
Sinan

Reputation: 5980

I'm not sure what you mean by date variable but. You can try these.

mktime()

mktime(0, 0, 0, $date, $month, $year)

or you can create a DateTime Object

$date = new DateTime('2000-01-01');

or you can try strtotime() if you have strings in your variables.

Upvotes: 1

user825607
user825607

Reputation:

So you'd want something like this:

date("d-M-Y", mktime(0, 0, 0, $month, $day, $year));

EDIT: Oops, sorry, fixed.

Upvotes: 1

Related Questions