Julian day of year

This is a discussion on Julian day of year within the C Programming forums, part of the General Programming Boards category; Folks, I'm trying to program some code that will return me the julian day of year, that means the day ...

  1. #1
    Marcelo, o Wuo
    Join Date
    Jun 2005
    Location
    Mogi das Cruzes, SP, Brasil
    Posts
    4

    Julian day of year

    Folks,
    I'm trying to program some code that will return me the julian day of year, that means the day from 1 to 365 (or 366 in leap years).

    All I need the specific part of code to do is: Get TODAY's Julian day value and put it as a number, int variable would do.

    Thanks for the help,

  2. #2
    Bob Dole for '08 B0bDole's Avatar
    Join Date
    Sep 2004
    Posts
    618
    Show us what you got so far
    Hmm

  3. #3
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  4. #4
    Marcelo, o Wuo
    Join Date
    Jun 2005
    Location
    Mogi das Cruzes, SP, Brasil
    Posts
    4

    Nothing yet

    I guess I should have asked how to use the time.h functions... Actually, I have very few knowledge on those functions work.

    Is there any way I can just command the code to get me the day of the current date and convert it to julian myself ???

    Thanks and sorry for asking the question in a bad way...

  5. #5
    Marcelo, o Wuo
    Join Date
    Jun 2005
    Location
    Mogi das Cruzes, SP, Brasil
    Posts
    4

    Day of year

    After reading that, I can only feel myself a little more dumb.

    So what I really need is the "day of year". Got a clue or have a nice tutorial I can dive in reading to learn the time.h funcions ???

    Thanks

  6. #6
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    Code:
    #include <stdio.h>
    #include <time.h>
    
    int main(void)
    {
       time_t now;
       if ( time(&now) != (time_t)(-1) )
       {
          struct tm *mytime = localtime(&now);
          if ( mytime )
          {
             char jday [ 4 ];
             if ( strftime(jday, sizeof jday, "%j", mytime) )
             {
                printf("mytime->tm_yday = %d, jday = \"%s\"\n", mytime->tm_yday, jday);
             }
          }
       }
       return 0;
    }
    
    /* my output
    mytime->tm_yday = 165, jday = "166"
    */
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  7. #7
    Marcelo, o Wuo
    Join Date
    Jun 2005
    Location
    Mogi das Cruzes, SP, Brasil
    Posts
    4

    Thanks

    Thanks everyone for helping.

    Dave, I was insipired by one post of yours in another thread and it worked. Thanks too!!

    See ya

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Calendar Problem
    By wordup in forum C Programming
    Replies: 7
    Last Post: 10-29-2002, 02:36 PM
  2. error with code
    By duffy in forum C Programming
    Replies: 8
    Last Post: 10-22-2002, 09:45 PM
  3. cant get code to work
    By duffy in forum C Programming
    Replies: 13
    Last Post: 10-20-2002, 05:23 AM
  4. debug program
    By new_c in forum C Programming
    Replies: 3
    Last Post: 03-18-2002, 10:50 PM
  5. Simplified code
    By soonerfan in forum C Programming
    Replies: 2
    Last Post: 12-05-2001, 02:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21