2
$doba = explode("/", $dob);

$date = date("Y-m-d", mktime(0,0,0, $doba[0], $doba[1], $doba[2]));

The above code turns any date i pass through into 1999-11-30 and i know it was working yesterday. Date is correct when I echo $doba. Anyone have any ideas?

Cheers

1
  • You need to show us the values you are passing in as $dob for us to give a definitive answer. Commented Oct 29, 2008 at 14:58

4 Answers 4

3

or even easier: $date = date('Y-m-d', strtotime($dob))

Sign up to request clarification or add additional context in comments.

Comments

2

What is the format of $doba? Remember mktime's syntax goes hour, minute, second, month, day year which can be confusing.

Here's some examples:

$doba = explode('/', '1991/08/03');
echo(date('Y-m-d', mktime(0,0,0, $doba[1], $doba[2], $doba[0]);

$doba = explode('/', '03/08/1991');
echo(date('Y-m-d', mktime(0,0,0, $doba[1], $doba[0], $doba[2]);

Comments

1

It is a bit overkill to use mktime in this case. Assuming $dob is in the following format:

MM/DD/YYYY

you could just to the following to acheive the same result (assuming $dob is always valid):

$doba = explode("/", $dob);
$date = vsprintf('%3$04d-%1$02d-%2$02d', $doba);

Comments

0

If you have issues with what jcoby said above, the strptime() command gives you more control by allowing you to specify the format as well.

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.