Jump to content

Date help


ruddernz

Recommended Posts

Can I suggest a solution that may not be the easy way, because I don't know if there is an easy way?

Create a loop that works like this:

create a variable that is the current month.
subtract 1 from that month.
create a variable that is the last day of that month
echo every day/date in a loop that counts backward until the day==friday

;-P
Link to comment
https://forums.phpfreaks.com/topic/5654-date-help/#findComment-20241
Share on other sites

Here is a function I finally came up with ....
[code]<?php
function last_friday($dt='today') {
    $prev = date('Y-m-d',strtotime('-1 month',strtotime($dt)));
    $lday = date('t',strtotime($prev));
    $prevm = date('m',strtotime($prev));
    $prevy = date('Y',strtotime($prev));
    $ld = date('Y-m-d',strtotime($prevm . '/' . $lday . '/' . $prevy));
    if (date('l',strtotime($ld)) == 'Friday') return $ld;
    else return date('Y-m-d',strtotime('last friday',strtotime($ld)));
}?>[/code]

Ken

(Why this originally posted twice)
Link to comment
https://forums.phpfreaks.com/topic/5654-date-help/#findComment-20444
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.