开发者

How can i get a year by using only days and months?

开发者 https://www.devze.com 2023-01-29 22:36 出处:网络
Requirements: f开发者_如何学运维unction arguments: - $day, $month function should return the year.

Requirements: f开发者_如何学运维unction arguments: - $day, $month function should return the year.

Is this possible ?


No. You're not giving the function even remotely enough information to be able to determine the year. Here's why:

I was born on March 2nd. Since I've given you the day and the month, please tell me what year I was born in.

Can't do it? Neither can a computer.

Sorry to be harsh, but the question makes no sense.


If the date picked is always in the future within a year, you can do this:

function next_date($m, $d)
{
  $s = sprintf('%02d-%02d', $m, $d);
  $y = date('Y');
  if (date('m-d') > $s) ++$y;
  return "$y-$s";
}

So if you pick a date between today and the end of this calendar year, it returns this year. Else it returns next year.

Such a date picker could be useful if you know the date being picked is never in the past and it's always within the next year. If that describes the type of date you are working with, then this is probably the behavior the client expects.

Otherwise, either your client is completely clueless or you misunderstood what they asked.

0

精彩评论

暂无评论...
验证码 换一张
取 消