mysql日期返回周一_MYSQL如何获得指定日期所在周周一的日期?

你的位置:

问答吧

-> PHP基础

-> 问题详情

MYSQL如何获得指定日期所在周周一的日期?

如何获得指定日期所在周周一的日期?比如如何获得本周周一的日期?

作者: 十月冷风

发布时间: 2007-06-07

原来所有系统里都是一周从周日开始算的,自己写了个函数

这个函数可以得到当前日期所在周的周日日期:lol

复制PHP内容到剪贴板

PHP代码:function getsunday(){

$year=date("Y");

$month=date("m");

$day=date("d");

$week=date("w");

$date_str=date("Y-m-d",mktime(0, 0, 0, $month, $day-$week, $year));

return $date_str;

}

作者: 十月冷风

发布时间: 2007-06-07

你这个是用PHP实现的,可以直接用MYSQL实现啊,

其中curdate是你所要查询的日期,得到周一的,周日用0

mysql> select subdate(curdate(),date_format(curdate(),'%w')-1);

+--------------------------------------------------+

| subdate(curdate(),date_format(curdate(),'%w')-1) |

+--------------------------------------------------+

| 2007-06-04                                       |

+--------------------------------------------------+

1 row in set (0.00 sec)

[ 本帖最后由 lmhllr 于 2007-6-7 15:48 编辑 ]

作者: lmhllr

发布时间: 2007-06-07

引用:原帖由 十月冷风 于 2007-6-7 15:42 发表

原来所有系统里都是一周从周日开始算的,自己写了个函数

这个函数可以得到当前日期所在周的周日日期:lol

[php]

function getsunday(){

$year=date("Y");

$month=date("m");

$day=date("d");

$week=date ...这个函数不错!

中国人的习惯总是以星期一为每周的第一天,而计算机是以星期天为每周的第一天

应该可以转换过来的吧?

思考一下...

作者: fly1983

发布时间: 2007-06-07

mysql的date_format有u和v可以格式化周一为第一天

作者: lmhllr

发布时间: 2007-06-07

array getdate ( [int timestamp] )

返回值是个关联数组.

"mday" Numeric representation of the day of the month 1 to 31

"wday" Numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday)

"yday" Numeric representation of the day of the year 0 through 365

"weekday" A full textual representation of the day of the week Sunday through Saturday

"month" A full textual representation of a month, such as January or March January through December

$today = getdate();

print_r($today);

?>

The above example will output something similar to:

Array

(

[seconds] => 40

[minutes] => 58

[hours]   => 21

[mday]    => 17

[wday]    => 2

[mon]     => 6

[year]    => 2003

[yday]    => 167

[weekday] => Tuesday

[month]   => June

[0]       => 1055901520

)

$array = getdate();

$array['wday'] 就是一个星期的第几天了.算一下就可以求出星期一来.

$today = getdate();

$w = time() - ($today['wday'] - 1 )* 24 * 3600;

$wmonday = date("Y-m-d", $w);

echo $wmonday;

?>

[ 本帖最后由 angeljyt 于 2007-6-7 18:23 编辑 ]

作者: angeljyt

发布时间: 2007-06-07

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值