Posted on 2003-03-19
Medium Priority
Last Modified: 2011-04-14
I have a Problem.
I am working on something like Message Forums.
Every Post Is Displayed only for 4 days Publically after Its Posted.
I store the date_entered values as time() in database (ie $now = time() and then store $now in date_entered field).

WHile Displaying the posts, I do Grouping
ie 1st Day, 2nd Day, 3rd Day and Final Day.
So those Posts which are Posted today come Under 1st Day Heading.

Problem is I dont have to count weekends(saturday/sundays) and some holidays that are defined by admin. So if I post on Monday and Monday is a holiday, Monday and Tuesday both will be the First Day.

If I post on Saturday, then sat/sun/mon will be First day (if monday is not a holiday). If monday is a holiday, then sat/sun/mon/tue all will be first day.

I hope I made myself clear.

How do I achieve this. I am all lost.
I have decided the best way to do is keep 4 fields in database (firstday, secondday, thirdday, fourthday) and while Inserting, do the calculations and insert proper values.  This way while displaying I can just select and Display, no hard calculations.

Any Code Samples for this?

Question by:desisant
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1

Accepted Solution

carchitect earned 600 total points
ID: 8165311
my answer is little idiotic....

take two var...firstday and lastday....

make a table of dates which are not holidays....now fill both var...

firstday will be fielddate from table which is less than equal to today's date and fielddate is

like select max(date) from notholiday where date <=todays date

this way you will get first date which is not holiday....
then look to fill lastday....

select date from notholiday where date <=todaydate limit by 0,4

now just insert last row value in lastday

print all those records which comes between firstday and lastday


LVL 15

Assisted Solution

VGR earned 600 total points
ID: 8165379
not that bad carchitect :D

Other solution less consuming in tablespace :
-you are supposed to be able to find the holidays in a table somewhere. Let's say I can use IsNotHoliday($date) : Boolean;

-you can select easily "next Monday" using PHP (see Doc on date() or strtotime()  I guess)

-I suggest this algorithm :
+start from the now() date of input in the DB - BTW, you don't have to do $now=date() and "date_entered='$now'" in MySql query : just set "date_entered=now()" in MySql query ;-)
+if rank in week is >Friday (see doc about this format, sometimes 1 is Monday, sometimes it's - stupidly - Sunday), set it to next Monday
+check if IsNotHoliday(that Monday), if yes you're done
+if not, increment day of date until IsNotHoliday(date)
(this is supposed to happen in less than 3 queries)

Author Comment

ID: 8165515

Could u help me with coding your algo.
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users


Author Comment

ID: 8165944
I have solved my Problem....Thanks Guys!

Expert Comment

ID: 8166189
hey could you pls post your solution
it will help us
LVL 15

Expert Comment

ID: 8168433

Expert Comment

ID: 11925353

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question