4

I have a Credit card expiry date with month and year only coming in form of a string say 08/17, How can I change this string in a format so that I can pass it to Authorize.net

$creditCard->setExpirationDate( "2017-08");

I have tried to use strtotime() but it is giving me the current year

echo $date = date('Y-m', strtotime($ccInfo['exp_date']));
baig772
  • 3,322
  • 11
  • 40
  • 88

2 Answers2

5

You should use date_create_from_format instead of strtotime to build your date:

echo date_create_from_format('m/y', '08/17')->format('Y-m');

The function creates a \DateTime object, so you can call format to get the format you want.

danopz
  • 3,170
  • 5
  • 29
  • 41
0

You can also write like this

$eventDate = DateTime::createFromFormat('m/y', '08/17');
echo date_format($eventDate, 'Y-m');
Rakesh Sojitra
  • 3,318
  • 2
  • 14
  • 31