monkeytooth Posted May 10, 2010 Share Posted May 10, 2010 Ok I have a 4 digit year stored in a database column.. I pull it out from the DB and I try to convert it to a 2 digit year. Which at first I thought was working fine.. Then i realized im only returning the current year. in 2 digit format. I though going the route of: $semister_year= date('y', strtotime($bcinfo1[0]['semister_year'])); would do me some justice but its not $bcinfo1[0]['semister_year'] Is the year.. coming from the DB.. any ideas? The years range I just want the two last digits.. example 2012 to 12 Link to comment https://forums.phpfreaks.com/topic/201254-php-yyyy-to-yy-confused/ Share on other sites More sharing options...
Mchl Posted May 10, 2010 Share Posted May 10, 2010 strtotime can't convert just a year to timestamp. It needs full date at least. Anyway, keep it simple. $semister_year = substr($bcinfo1[0]['semister_year'],2,2) Link to comment https://forums.phpfreaks.com/topic/201254-php-yyyy-to-yy-confused/#findComment-1055800 Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 The string "2012" is not a valid date to the strtotime() function. Just add the string "-01-01" to it and it will work: <?php $semister_year= date('y', strtotime($bcinfo1[0]['semister_year']) . '-01-01'); ?> Ken Link to comment https://forums.phpfreaks.com/topic/201254-php-yyyy-to-yy-confused/#findComment-1055801 Share on other sites More sharing options...
monkeytooth Posted May 10, 2010 Author Share Posted May 10, 2010 substr, why didnt I think of that.. oi. Thank you for putting that in perspective :-) but both valid concepts.. thank you both. Link to comment https://forums.phpfreaks.com/topic/201254-php-yyyy-to-yy-confused/#findComment-1055803 Share on other sites More sharing options...
Mchl Posted May 10, 2010 Share Posted May 10, 2010 Actually, 2012 for strtotime means 'today 8:12pm' Link to comment https://forums.phpfreaks.com/topic/201254-php-yyyy-to-yy-confused/#findComment-1055805 Share on other sites More sharing options...
PFMaBiSmAd Posted May 10, 2010 Share Posted May 10, 2010 $semister_year = $bcinfo1[0]['semister_year'][2] . $bcinfo1[0]['semister_year'][3]; Link to comment https://forums.phpfreaks.com/topic/201254-php-yyyy-to-yy-confused/#findComment-1055810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.