Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 06-16-2022, 08:21 PM   #1
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,125
Date() countdown until last Sunday of the month?

I have the following code:

Quote:
$dt_end = new DateTime('June 26, 2022');
$remain = $dt_end->diff(new DateTime());
echo $remain->d . ' days and ' . $remain->h . ' hours';
How would I go about changing it so that each month, it will display the days until the last Sunday of the month without having to put the date in the code?

I've searched a few different places and can't find anything specific to what I need

Hopefully that makes sense?

TIA for any help you can offer.
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-16-2022, 08:28 PM   #2
baodb
Confirmed User
 
Industry Role:
Join Date: Jan 2021
Posts: 103
Did you try 'last Sunday of the month'? PHP surprisingly can parse a lot of these things and do the heavy lifting for you
baodb is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-16-2022, 08:33 PM   #3
sarettah
see you later, I'm gone
 
Industry Role:
Join Date: Oct 2002
Posts: 14,070
Google is your friend.

https://rosettacode.org/wiki/Find_th...each_month#PHP

Like baodb said, you can use the string "last sunday of month year" in the date function to get the date of the last sunday.

date('Y-m-d', strtotime('last sunday of ' . $month . ' ' . $year)

Here is an example they have looping through and getting the last sunday of every month.

// Created with PHP 7.0

function printLastSundayOfAllMonth($year)
{
$months = array(
'January', 'February', 'March', 'April', 'June', 'July',
'August', 'September', 'October', 'November', 'December');

foreach ($months as $month) {
echo $month . ': ' . date('Y-m-d', strtotime('last sunday of ' . $month . ' ' . $year)) . "\n";
}
}

printLastSundayOfAllMonth($argv[1]);

.
__________________
All cookies cleared!
sarettah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-16-2022, 08:59 PM   #4
Publisher Bucks
Confirmed User
 
Industry Role:
Join Date: Oct 2018
Location: New Orleans, Louisiana. / Newcastle, England.
Posts: 1,125
I swear I searched for this in Google and Sitepoint and nothing came up :/

Thank you both.
__________________
SOMETHING EXTREME IS COMING SOON!
Publisher Bucks is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-16-2022, 09:38 PM   #5
fuzebox
making it rain
 
fuzebox's Avatar
 
Industry Role:
Join Date: Oct 2003
Location: seattle
Posts: 22,032
Really never came across strtotime??
fuzebox is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks

Tags
month, days, date, code, sunday, searched, offer, tia, countdown, makes, sense, specific, display, $dt_end-diffnew, $remain, datetime;, echo, $remain-d, 2022;, $dt_end, datetimejune, $remain-h, hours;, changing



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.