Finding out the day of the year it is. (Not what you think.)
Moderator: General Moderators
Finding out the day of the year it is. (Not what you think.)
I'm not talking about using date(); to find out what day of the year it is. I want to find out the day of the year it is.
For example: January 18th, is the 18th day of the year, Febuary 1st is the 31st day of the year, you know what I mean? I'm well aware that date(); provides a function to do this. But I want to do something such as 01 (january) 18(day), and the program to say, this is the 18th day of the year, not find the current day, understand?
please help.
For example: January 18th, is the 18th day of the year, Febuary 1st is the 31st day of the year, you know what I mean? I'm well aware that date(); provides a function to do this. But I want to do something such as 01 (january) 18(day), and the program to say, this is the 18th day of the year, not find the current day, understand?
please help.
Code: Select all
echo "This is the " . date("zS") . " day of the year.";Jza wrote:this produces 364, december 31th is the 365th day of the year, is it not?
You can increment the value if you want to, e.g.http://de2.php.net/date wrote:z The day of the year (starting from 0)
Code: Select all
<?php
$d = getdate( mktime(12, 0, 0, 12, 31, 2006) );
echo $d['yday'] + 1;
?>Code: Select all
preg_match('#([0-9]{1,3})([a-z]{0,2})#i', date("zS"), $x);
echo "This is the " . ($x['1'] + 1) . $x['2'] . " day of the year.";
Last edited by Benjamin on Tue Sep 26, 2006 5:59 pm, edited 1 time in total.
It starts counting at 0. Check out
http://www.php.net/manual/en/function.date.php for more specifics on how it works.[/url]
http://www.php.net/manual/en/function.date.php for more specifics on how it works.[/url]
Code: Select all
preg_match('#([0-9]{1,3})([a-z]{0,2})#i', date("zS"), $x);
echo "This is the " . ($x['1'] + 1) . $x['2'] . " day of the year.";If the returned day is 1, you would see: "This is the 2th day of the year.";
Also the 'S' format character works for the day of the month.
The correct way:
date('z')+1. Check the last digit (after +1) and choose the correct ordinal suffix (st, nd, rd, th)