Return the last 2 digits a number

后端 未结 6 1036
Happy的楠姐
Happy的楠姐 2021-01-11 15:00

How can I get the last 2 digits of:

200912

to my object:

$year = $flightDates-&         


        
6条回答
  •  滥情空心
    2021-01-11 15:01

    // first two
    $year = substr($flightDates->departureDate->year, 0, 2);
    // last two
    $year = substr($flightDates->departureDate->year, -2);
    

    But given the fact that you're parsing a date here it would be smarter to use the date function. p.e. strtotime() and date() or even:

    format('Y');
    // prints "2012" .. (see date formats)
    

提交回复
热议问题