calculate leap year
Page 1 of 1
calculate leap year
#2
Posted 05 April 2007 - 04:50 AM
shamala, on 5 Apr, 2007 - 04:46 PM, said:
can anybody help me in displaying the number of days by checking leap year for February?
I am just learning the PHP ....actually i am working as a Sr. designer in nagpur(INDIA).
just have joined the classes of PHP.
thanks
I am just learning the PHP ....actually i am working as a Sr. designer in nagpur(INDIA).
just have joined the classes of PHP.
thanks
logic of checking leap year does not change with language.
it will remain same.
you need to accept the year value from user, apply logic to find whethere it is a leap year. and display the result.
it's only your way of taking input and output is changing.
now when you accept info from textbox [year] , just mod it with 400 and 4. it will give answer of whether it is leap year or not.
and in case of accepting it I guess you can accept it from a text box.
and can print it as a simple HTML thing.
like
<?php if(!leapYear) { ?>
This is not a leap year.
<?php } else { ?>
This is a leap year.
<?php } ?>
well you can do better than this.
try it and still if you have problem then put your code here.
ya and www.php.net is one of the best sites for PHP.
This post has been edited by AmitTheInfinity: 05 April 2007 - 04:53 AM
#3
Posted 05 April 2007 - 11:15 AM
The number of days? There are many ways to do that:
Read how to use the date function. You can use 't' to get the number of days in a month by specifying a timestamp (using mktime).
Use the function cal_days_in_month to get the number of days by specifying a calendar, the month, and the year.
Use strtotime and date to get the number of days by requesting the next month's first day and adding on '-1 day' then parsing through strtotime to get the timestamp of the last day. Use 'j' in date to get the actual number.
Or you could make an array of numbers for each month and, when processing, check with modulus if it's a leapyear, then display the number from the array.
Read how to use the date function. You can use 't' to get the number of days in a month by specifying a timestamp (using mktime).
Use the function cal_days_in_month to get the number of days by specifying a calendar, the month, and the year.
Use strtotime and date to get the number of days by requesting the next month's first day and adding on '-1 day' then parsing through strtotime to get the timestamp of the last day. Use 'j' in date to get the actual number.
Or you could make an array of numbers for each month and, when processing, check with modulus if it's a leapyear, then display the number from the array.
Page 1 of 1

Start a new topic
Add Reply




MultiQuote
| 


