Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 548
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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