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,404
  • 11
  • 48
  • 93

2 Answers2

6

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,310
  • 5
  • 31
  • 42
0

You can also write like this

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