Solved

Date Format YYDDD (julian?)

Posted on 2004-08-04
9
493 Views
Last Modified: 2012-05-05
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
Comment
Question by:jmsloan
  • 4
  • 3
  • 2
9 Comments
 
LVL 33

Assisted Solution

by:snoyes_jw
snoyes_jw earned 30 total points
ID: 11717859
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
 
LVL 3

Author Comment

by:jmsloan
ID: 11717958
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
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 11718008
as I said, date("yz") + 1;
0
 
LVL 27

Accepted Solution

by:
Diablo84 earned 20 total points
ID: 11718022
try

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

echo $out;
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 27

Expert Comment

by:Diablo84
ID: 11718026
sorry, should be

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

echo $out;
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 11718029
ah, but then we lose leading zeros.  I'll find it here in a second...
0
 
LVL 33

Expert Comment

by:snoyes_jw
ID: 11718038
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
 
LVL 27

Expert Comment

by:Diablo84
ID: 11718059
true, so...

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

echo $out;
0
 
LVL 3

Author Comment

by:jmsloan
ID: 11718668
Sorry that should have been the other way around
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now