-2

Possible Duplicate:
Strtotime() doesn’t work with dd/mm/YYYY format

I have this variable which i get the info like this:

echo $start=$_REQUEST['to'];

It outputs something like this:

2/04/2012

What i need is to convert it like this: 20120402 Could you please help me? I tried strotime and no success.. I tried converting the string before in a date format, then i converted it in a Ymd format, but i kept receiving a strange date, something like 1970 ! I tried this:

$time = strtotime( $date );
$myDate = date( 'y-m-d', $time );

thanks!

Community
  • 1
  • 1
al_alb
  • 145
  • 1
  • 2
  • 8
  • Please show complete code which does not work. Dates being formatted as 1970 typically means `strtotime` could not parse the date format and returned `0` == 1/1/1970. In your case `strtotime` does seem to parse the format correctly, and the `date` call should work just fine. The question is incoherent. – deceze Dec 04 '12 at 08:23
  • $d = DateTime::createFromFormat('d/m/Y', '23/02/2012'); $d->format('Y-m-d'); – galchen Dec 04 '12 at 16:13

2 Answers2

1

It may work.

<?php
$start=$_REQUEST['to'];
$date = explode("/",$start);
$size = sizeof($date);
for($i=$size;$i>=0;$i--) {
    $date_get .= $date[$i];
}
echo $date_get;
?>
Prem
  • 697
  • 3
  • 10
0

You should use strftime instead of date.

$myDate = strftime('%Y%m%d', $time);
deceze
  • 510,633
  • 85
  • 743
  • 889
Stanley
  • 5,057
  • 4
  • 34
  • 44