Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Calculate date of "next sunday" 1

Status
Not open for further replies.

Microbe

Programmer
Oct 16, 2000
607
AU
Hey there, how do I calculate the date of "next Sunday"?

Thanks in advance

Steve Davis

NOTE: This sig does not include any reference to voting, stars, or marking posts as helpful as doing so is cause for membership termination.
 
Hi, look at this:
You can check the wday diff vs. todays wday..
eg. Sunday = 0, if wday == 1, you know that it's 6 - 1 days untill it's sunday.

It's way more simple in mysql though, so if you are querying your db, I would do it there..

Eg. you could do in mysql:
Code:
mysql> SELECT STR_TO_DATE('200442 Monday', '%X%V %W');
        -> '2004-10-18'

Or, you could use PHP and mysql, pass the difference from above and use the DATE_ADD mysql function, in cooperation with now() / timestamp.

There might be a way to do it in php too, but I think it's easiest to do it in mysql, if your running a query when you want it extracted.


Olav Alexander Mjelde
Admin & Webmaster
 
Code:
date ("j/m/Y", strtotime("next Sunday"));

yup - it's that easy...
 
Thanks for that

I am doing the calculation to put a default "week ending date" into a form, so jpadie's answer is perfect.

I appreciate you both answering.

Steve Davis

NOTE: This sig does not include any reference to voting, stars, or marking posts as helpful as doing so is cause for membership termination.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top