함수 ordinaldate2date()

1 개요[ | ]

ordinal date to date
  • ISO-8601
  • test set
2005-001 → 2005-01-01
2005-002 → 2005-01-02
2005-365 → 2005-12-31
2007-001 → 2007-01-01
2007-364 → 2007-12-30
2007-365 → 2007-12-31
2008-001 → 2008-01-01
2008-364 → 2008-12-29
2008-366 → 2008-12-31
2009-001 → 2009-01-01
2009-365 → 2009-12-31
2010-003 → 2010-01-03

2 Excel[ | ]

=DATE(LEFT(A1,4),1,RIGHT(A1,3))
=DATE(LEFT("2008-366",4),1,RIGHT("2008-366",3))
//2008-12-31

3 PHP[ | ]

$ordinal_date = '2008-366';
$date = date('Y-m-d', strtotime(substr($ordinal_date,0,4).'-01-00 +'.substr($ordinal_date,-3).' day'));
echo $date; // 2008-12-31
function ordinaldate2date($ordinal_date) {
  $arr = explode('-', $ordinal_date);
  return date('Y-m-d', strtotime($arr[0].'-01-00 +'.$arr[1].' day'));
}

$ordinal_date = '2008-366';
$date = ordinaldate2date($ordinal_date);
echo $date; // 2008-12-31

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}