duanjue9296 2014-05-14 15:23
浏览 19

PHP:转换为日期格式的问题

I found the following function on the PHP Manual page that calculates the Orthodox Easter date (source: http://www.php.net/manual/en/function.easter-date.php).

function easterOrthodox_date($year) { 
    $a = $year % 4; 
    $b = $year % 7; 
    $c = $year % 19; 
    $d = (19 * $c + 15) % 30; 
    $e = (2 * $a + 4 * $b - $d + 34) % 7; 
    $month = floor(($d + $e + 114) / 31); 
    $day = (($d + $e + 114) % 31) + 1; 

    $de = mktime(0, 0, 0, $month, $day + 13, $year); 

    return $de; 
}

I am using the following line to get this date for a certain year (selYear):

$EasterOrth = date('Y-m-d', easterOrthodox_date($selYear));

When I echo the result on my page this looks correct and shows 2014-04-20 (which is correct as for this year it is the same date as for the catholic Easter).

However, when I use this for other calculations it returns wrong results, e.g. the Dec 31. Is it possible that in this case I need to format this differently in order to get a date with the format yyyy-mm-dd ?

Update: The above variable is being passed to a stored procedure in SQL where I run the following Select (part of a longer query):

SELECT      DATEADD(d, daysFromEaster, @EasterOrth) AS dayX,
            category1,
            category2,
            '' AS validity
FROM        DayCheck_Easter
WHERE       mode = 'EasterOrth'

This should only fetch items from a table where the mode is set to EasterOrth and it seems the issue is with the first line here where I am adding a number of days (int). It works fine in several other Selects but here it calculates the wrong dates which is why I thought my formatting is wrong so that it isnt recognised as date.

Thanks, Mike.

  • 写回答

1条回答 默认 最新

  • dsf22567 2014-05-14 16:05
    关注

    I found the issue - it was neither the PHP nor the SQL but a typo in the Ajax that passes the variable which is why SQL couldn't read it properly.

    Thanks again for all the help - it pointed me in the right direction.

    评论

报告相同问题?

悬赏问题

  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多