RSS

Tag Archives: Year

Happy New Year!

I have seen couple of the times guys are struggling with question like below. If you are among the same please find this post as a help for you.

Q: On which of the two days of the week, Saturday or Sunday, does New Year’s Day fall more often? Explain your reasoning and write the corresponding PHP code to prove your answer.

I would share a reasoning for the above question. And I am sure you guys would be pretty good to convert it into a programme. If still you have any issue feel free to write me to help you even with code snippet also.

In the coming 400 years from 2001 to 2400, Saturday and Sunday both will occur equal 57 times on the New Year eve.

REASONING

ð  Every fourth year is a leap year. 2004, 2008, and 2012 are leap years.
ð  However, every hundredth year is not a leap year. 2100, 2200 and 2300 are not leap years.
ð  Every four hundred years, there’s a leap year after all. 2000 and 2400 are leap years.

For A Non Leap Year, i.e; 2001, 2002, 2003

No. of Days = 365

No. of Weeks = 365/7 = 52 Weeks + One Day

ð  The year starts with the day of the week will complete on the same day, and the next year will start with the next successive day of the week.

For example:

Ist Jan 2001 – Monday

So,

31st Jan 2001 – Monday

1st Jan 2002 – Tuesday…..and so far till leap year doesn’t come.

For A Leap Year, i.e; 2004, 2008, 2012

No. of Days = 366

No. of Weeks = 366/7 = 52 Weeks + Two Days

ð  The year starts with the day of the week will complete on the next day, and the next year will start with the next to next successive day of the week.

For example:

Ist Jan 2004 – Thursday

So,

31st Jan 2004 – Friday

1st Jan 2005 – Saturday…..and so far

As per the logic described above please find the below PHP program which will output the following:

Total No. of Sunday’s count on New Year: 58
Total No. of Saturday’s count on New Year: 56

I have written the code for the same by using the below two functions, you are free to use the same concept or something new

  1. checkLeap ~ To identify the particular year is a Leap year or not.
  2. newYearDay  ~ To find the first day of the year as per the Leap year and Non Leap year condition.

I hope the above explanation will work for you to generate a programme for the scenario!

 
Leave a comment

Posted by on January 18, 2014 in PHP

 

Tags: , , , , , , , ,

Calendar (PHP)

Last time i had written a blog, Calendar (jQuery) — A calendar on client side. This time i am going to share code snippet for how to build a calendar with PHP. Actually its very simple. And sometimes we have requirement to play with data on date. Then the calendar operate on server side is really very helpful and make things simple for us. Just go through the below attached code. Having function calendar( $date )  {  }. May be to understand the functionality of few of the functions used with-in  the “calendar” we need to refer this.

With the help of above function we can build a PHP calendar something like this and play with the data on date.

 
Leave a comment

Posted by on February 15, 2011 in PHP

 

Tags: , , , , ,