Results 1 to 6 of 6

Thread: Help in finding the current day of the year in PHP

  1. #1
    Join Date
    Dec 2009
    Posts
    12

    Help in finding the current day of the year in PHP

    I am new(means the beginner) to this advance level of programming world. Now a days, i am learning the programing language like C++, C sharp, .Net, Java, and PHP. I have a query in the PHP, i want know is there any standard function which can give me the current day of the year.
    Example: Jan 14=14 , Feb 2= 33, April 1= 91
    Please help me in getting this code.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Help in finding the current day of the year in PHP

    PHP(Hypertext Prepocessor) is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML. Most of the people gets confused in getting the output you told. And yes there is a function in PHP to get output you told, and the function is date. Date function is very useful in PHP, it has many sub function in it.
    Example:
    // if you want to get day of year for 06 august 2010
    // result should be 219
    echo date("z", mktime(0,0,0,6,8,2010))+1;
    Hope this will work for you and would able to achieve your aim.
    Last edited by Modifier; 23-01-2010 at 09:19 AM.

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Help in finding the current day of the year in PHP

    According to your question, i think you want the function that will find the day in year for any particular date. If this is really the meaning of your question, then it can be achieve by using the date() function of the PHP and also with the 'z' modifier. For example:
    <?php
    // get day of year for 1 Feb 2010
    // result will be 31
    echo date("z", mktime(0,0,0,1,2,2010))+1;
    ?>
    This code should work for you.

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: Help in finding the current day of the year in PHP

    I am also learning the PHP language and i am enjoying with it. This really simple and easy language to learn. The output you want to achieve can be done with the help of date function. The date() function can be used in a good way, in some cases, and the most common place you would probably be to display the current date. For your purpose use date function with "z - Day of the year (0-365)" option.

  5. #5
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Help in finding the current day of the year in PHP

    My studies of the PHP language says that there possible standard function to achieve your goal. The PHP date() function will be used to achieve your goal, this function formats a timestamp to a more readable date and time. There are are two paratmeters of this function i.e format(required) and timestamp(optional). You have to use "z" character which will format the date as you wanted (i.e the day in year for any particular date).
    Syntax: date("z",...)
    Hope your problem will be fix.

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Help in finding the current day of the year in PHP

    I also had same problem few days ago, and the output you wanted was given as an mini project to me from my professor. By keeping in mind that you would be knowing PHP basics and the output you want can be achieved through date() function only. The code would be somewhat like this:
    <?php
    // get day of year for 14 Feb 2010
    // result will be 45
    echo date("z", mktime(0,0,0,14,2,2010))+1;
    ?>
    This code given to me by my professor, it worked for me, hope it will work for you also.

Similar Threads

  1. Need help finding a UPS for my current rig
    By Danvir in forum Hardware Peripherals
    Replies: 5
    Last Post: 21-11-2010, 02:28 AM
  2. Finding database name and PID
    By Adriana_andros in forum Software Development
    Replies: 5
    Last Post: 16-02-2010, 06:47 PM
  3. Online threats for the current year
    By Aandaleeb in forum Networking & Security
    Replies: 5
    Last Post: 13-01-2010, 12:22 AM
  4. How to write a program to determine if year is leap year or not
    By Luis-Fernando in forum Software Development
    Replies: 4
    Last Post: 30-11-2009, 05:21 PM
  5. How to get Current year with javascript
    By Waman in forum Software Development
    Replies: 2
    Last Post: 22-05-2009, 10:52 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,514,642.34575 seconds with 16 queries