• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 565
  • Last Modified:

Date Format YYDDD (julian?)

Hello I am looking to get a day format of YYDDD i think it is a julian day.  

when i do

echo date("yz");
 
it gives me 04216, but with leap year the actual date is 04217.

Does anyone know how I can get the actual julian day?
0
jmsloan
Asked:
jmsloan
  • 4
  • 3
  • 2
2 Solutions
 
snoyes_jwCommented:
z gives the day of the year starting with 0.  If you want it starting with 1, just add one.
echo date("yz") + 1;
0
 
jmsloanAuthor Commented:
what is going to give me the format i need  YYDDD

what if it is the 2 day of the year I need it to say

04002
0
 
snoyes_jwCommented:
as I said, date("yz") + 1;
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Diablo84Commented:
try

$var = date("y");
$var2 = date("z");
$var2 = str_pad($input, 3, "0", STR_PAD_LEFT);
$out = $var.$var2;

echo $out;
0
 
Diablo84Commented:
sorry, should be

$var = date("y");
$var2 = date("z");
$var2 = str_pad($var2, 3, "0", STR_PAD_LEFT);
$out = $var.$var2;

echo $out;
0
 
snoyes_jwCommented:
ah, but then we lose leading zeros.  I'll find it here in a second...
0
 
snoyes_jwCommented:
There, what Diablo84 said, but you'll still need to increment it, otherwise the first day of the year will come out as 04000.
0
 
Diablo84Commented:
true, so...

$var = date("y");
$var2 = date("z") +1;
$var2 = str_pad($var2, 3, "0", STR_PAD_LEFT);
$out = $var.$var2;

echo $out;
0
 
jmsloanAuthor Commented:
Sorry that should have been the other way around
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now