dousi1970 2014-01-21 14:21
浏览 22
已采纳

如何通过php或jquery获得当前周的5个日期?

i have this and yesterday it worked fine, but not today.

$current_dayname = date("l");    
$datemon = date("m-d-Y",strtotime('monday this week'));
$datetue = date("m-d-Y",strtotime("tuesday this week"));
$datewed = date("m-d-Y",strtotime("wednesday this week"));
$datethu = date("m-d-Y",strtotime("thursday this week"));
$datefri = date("m-d-Y",strtotime("friday this week"));

yesterday, $datemon through $datefri would get the values of 1-20-2014 through 1-24-2014, but today only tuesday through friday is working and monday is getting the date for next monday, not yesterday.

how can i get the dates of the 5 weekdays of the current week? so if it's wednesday for example, the 5 variables should be 2 for 2 days past, 1 for current day, and 2 for future days. know what i mean?

i'm going to guess that someone will ask if week starts with monday or sunday. doesn't really matter as long as script works, but the week starting on a monday is preferable.

  • 写回答

2条回答 默认 最新

  • dtt2012 2014-01-21 14:34
    关注

    An easier way to get those dates might be something like this:

    $today = time();
    $wday = date('w', $today);   
    $datemon = date('m-d-Y', $today - ($wday - 1)*86400);
    $datetue = date('m-d-Y', $today - ($wday - 2)*86400);
    $datewed = date('m-d-Y', $today - ($wday - 3)*86400);
    $datethu = date('m-d-Y', $today - ($wday - 4)*86400);
    $datefri = date('m-d-Y', $today - ($wday - 5)*86400);
    

    I would also recommend using an array instead of 5 different variables, but that's a separate concern.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100