如何找到最近的过去星期一? [英] How to find the most recent past Monday?

查看:177
本文介绍了如何找到最近的过去星期一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ColdFusion 9.0.1。

I am using ColdFusion 9.0.1.

我每个星期一在午夜创建比赛。我需要使用ColdFusion(但我相信其他语言的逻辑是一样的)找到最近一个星期一的日期。一旦我确定该日期,我将把该日期放入SQL语句以获得当前排名和过去的结果。

I am creating a contest each Monday at midnight. I need to use ColdFusion (but I am sure the logic is the same for other languages) to find the date of the most recent past Monday. Once I determine that date, I will drop that date into a SQL Statement to get the current standings and past results.

所以,我需要什么功能来找到最最近过去一周?

So, what functions do I need to find the most recent past Monday?

ANSWER

Dates = structNew();
Dates.CurrentDay = dateFormat(now(), "yyyy-mm-dd");
// LOOP MAX OF SEVEN TIMES
for (i = 1; i lte 7; i++) {
    // IF CURRENT DAY OF WEEK IS MONDAY SET AND BREAK
    if (dayOfWeek(Dates.CurrentDay) == 2) {
        Dates.BikeOfTheWeekDate = Dates.CurrentDay;
        break; 
    // IF CURRENT DAY OF WEEK IS NOT MONDAY SUBTRACT DAY
    } else {
        Dates.CurrentDay = dateAdd("d", -1, Dates.CurrentDay);
    }
}


推荐答案

Pseudocode :

Pseudocode:

Get the current day
Loop
    Check if it's Monday
        If yes, break out of the loop
    Substract one
Next loop



在ColdFusion中,日与 DateAdd(d,-1,日期)并检查星期一与 DayOfWeek(日期) 2为星期一。

In ColdFusion, substract one day with DateAdd("d", -1, date) and check for Monday with DayOfWeek(date) which returns 2 for Monday.

这篇关于如何找到最近的过去星期一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆