Getting file dates 
Author Message
 Getting file dates

File Dates
I'm looking for the PROCEDURE to calculate the date, time etc of a file,
given its integer value since 1970. I do not want references to a C
function or any other language on how to do it, I just want the proc used.
Any assistance will be appreciated.

John Hayes



Thu, 07 Oct 1999 03:00:00 GMT  
 Getting file dates


[...]

Quote:
>I'm looking for the PROCEDURE to calculate the date, time etc of a file,
>given its integer value since 1970. I do not want references to a C
>function or any other language on how to do it, I just want the proc used.

[...]

You need to specify your problem more clearly.  What is your input?
integer value IN WHAT UNIT since 1970?  A more correct formulation of
the problem might be:

  "Given an integer number of seconds since 00:00, Jan 1, 1970,
   what is the time/date represented?"

Notice that I filled in details that are crucial to the computation
that you did not specify.

Now, after you've formulated your question properly, how about giving
it some thinking yourself?  Here's a trivial solution:

  n = number of seconds since start of 1970, your input
  year = 1970

calculate_year:
  if (year is a leap year)
    if (n > number of seconds in a leap year)
      n -= number of seconds in a leap year
      year++
    else
      goto calculate_months
  else
    if (n > number of seconds in a non-leap year)
      n -= number of seconds in a non-leap year
      year++
    else
      goto calculate_months
  goto calculate_year

calculate_months:
  month = january
  if (n > number of seconds in january)
    n -= number of seconds in january
    month++
  else
    goto done
  if (year is a leap year)
    if (n > number of seconds in a leap year february)
      n -= number of seconds in a leap year february
    else
      goto done
  else
    if (n > number of seconds in a non-leap year february)
      n -= number of seconds in a non-leap year february
    else
      goto done
  [and so on and so forth]

done:
  day = 1 + n / number of seconds in a day
  [at this point (year, month, day) is the date represented by n]

The above should get you a grade of about C, if this is a homework
problem.  It's a pretty simpleminded and stupid solution, but it looks
too much like a homework problem to give it much thought.



Fri, 08 Oct 1999 03:00:00 GMT  
 Getting file dates


Quote:
> File Dates
> I'm looking for the PROCEDURE to calculate the date, time etc of a file,
> given its integer value since 1970. I do not want references to a C
> function or any other language on how to do it, I just want the proc used.

.....then perhaps you should try some other newgroup....is there a
comp.lang.dont.mention.c.?....G

Quote:
> Any assistance will be appreciate.

> John Hayes

....message ends.....


Thu, 14 Oct 1999 03:00:00 GMT  
 Getting file dates

Quote:


> > File Dates
> > I'm looking for the PROCEDURE to calculate the date, time etc of a file,
> > given its integer value since 1970. I do not want references to a C
> > function or any other language on how to do it, I just want the proc used.

> .....then perhaps you should try some other newgroup....is there a
> comp.lang.dont.mention.c.?....G

Maybe there is a comp.lang.useless.answers ...

Stephan



Fri, 15 Oct 1999 03:00:00 GMT  
 Getting file dates


Quote:


>> > File Dates
>> > I'm looking for the PROCEDURE to calculate the date, time etc of a file,
>> > given its integer value since 1970. I do not want references to a C
>> > function or any other language on how to do it, I just want the proc used.

*sigh*  How long until finals are over?!?!

Break the integer value into "seconds since midnight" and "days since
1970" with a single pair of division/modulo operations.  Reducing the
first to hours, minutes and seconds is trivial.

Reducing the latter to years, months and days is a little more complex,
but not by much.  With a little work you can reuse calendar equations
dating back hundreds of years, or use a couple small lookup tables.
Don't forget to account for leap years.

If you want more information convince me you aren't a college student
looking for help on your homework.  There are a lot of refinements
possible, but that's the difference between a high grade and a passing
one so I don't want to reveal too much.

--
Bear Giles        Learn how to reject spam mail with sendmail (8.8.5)!!

                  Demand your ISP upgrade and install filters today!!



Tue, 19 Oct 1999 03:00:00 GMT  
 Getting file dates

Quote:



> > > File Dates
> > > I'm looking for the PROCEDURE to calculate the date, time etc of a file,
> > > given its integer value since 1970. I do not want references to a C
> > > function or any other language on how to do it, I just want the proc used.

> > .....then perhaps you should try some other newgroup....is there a
> > comp.lang.dont.mention.c.?....G

> Maybe there is a comp.lang.useless.answers ...

....even if he had asked for an answer in C, the original request was
far too vague to provide anything helpful......but why post to a C
newsgroup explicitly requesting a non-C answer.....it was as useful an
answer as the question deserved.

G.

Quote:

> Stephan

....message ends.....


Tue, 19 Oct 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Getting file dates

2. Need help with getting the system date on the file server

3. Getting a file list based on creation date/time

4. getting file names and dates in a directory

5. Getting file creation dates from ifstream.

6. problem getting file modification dates

7. Getting the modified date of a file

8. Getting Number of Months and Days between two dates

9. getting time/date

10. Getting todays date?

11. Getting the week from a date.

12. Newbie needs help on C getting Unix's date

 

 
Powered by phpBB® Forum Software