School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,149 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,866 people online right now. Registration is fast and FREE... Join Now!



calculate leap year

calculate leap year Rate Topic: -----

#1 shamala  Icon User is offline

  • New D.I.C Head
  • Pip
  • Group: New Members
  • Posts: 1
  • Joined: 05-April 07


Dream Kudos: 0

Post icon  Posted 05 April 2007 - 03:16 AM

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
Was This Post Helpful? 0
  • +
  • -


#2 AmitTheInfinity  Icon User is offline

  • C Surfing ∞
  • Icon
  • Group: Authors
  • Posts: 1,384
  • Joined: 25-January 07


Dream Kudos: 125

Posted 05 April 2007 - 04:50 AM

View Postshamala, 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


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

Was This Post Helpful? 0
  • +
  • -

#3 Styx  Icon User is offline

  • D.I.C Head
  • Icon
  • Group: Contributors
  • Posts: 192
  • Joined: 04-March 07


Dream Kudos: 225

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.
Was This Post Helpful? 0
  • +
  • -



Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month