0

I have to manage every type of date.. I'm looking for the best way to manage date such as 600.000 a.c.e. or 5.000.000 years ago and the other kind of date format possible from the born of the earth

what would you suggest?

I'm blocked using a string format like: yyyyyyyyyy.mm.dd.v

where v is the ACE/BCE variable

[edit] if I start counting the day from the born of the earth, so 4.5mil years ago is the 1st day?

Mindexperiment
  • 145
  • 1
  • 10
  • 4
    I wonder what kind of application you are making that you need to store `3rd of March, 5.000.000 BC`. Are you making a time machine in PHP? – Bart Friederichs Jul 12 '13 at 13:55
  • 2
    And you need to specify an exact month and day as well? It raises some philosophical questions regarding date validity and precision. – mzedeler Jul 12 '13 at 13:59
  • the problem is that users can insert every type of date, but I need a unify method to use it.. the date can be from about 4.500.000.000 a.c. till the future.. the string I use has 10 char for the year so I can manage a good amount of time but I think there's a better way! – Mindexperiment Jul 12 '13 at 14:12
  • @mzedeler is not necessary to specify an exact day as well, I notice that sometime we refer to the past as "years ago" something like 600.000 years ago... how can I manage this? – Mindexperiment Jul 12 '13 at 14:15
  • @Mindexperiment `time() - 600000 * 365.25 * 86400` means 600000 years ago – baldrs Jul 12 '13 at 14:16
  • @Mindexperiment so you just want to recogize input and turn it into seconds – baldrs Jul 12 '13 at 14:17
  • not in seconds.. the whole day, the time is standard for every day so I don't have problem.. The real problem is that I can't insert in a mysql db a date like 25000/06/25 a.c. – Mindexperiment Jul 12 '13 at 14:25
  • But you can convert the date into seconds, assign it to a int64 field(or how it's called), and before out convert int back into human readable string. Or you can store text in the `varchar` fields. – baldrs Jul 12 '13 at 14:27
  • the varchar solution I think is the best way.. – Mindexperiment Jul 12 '13 at 14:30
  • yes, and today will be about 1.7155e+12 day from the beginning – baldrs Jul 12 '13 at 14:31

1 Answers1

4

You can use any number of seconds as your timestamp(consider your arch, of course)

Just remember any date is in seconds.

php > echo date('Y.m.d', 9000000000000000), "\n";
285200616.07.24
php > echo date('Y.m.d', -9000000000000000), "\n";
-285196677.06.10

As for AC/BC flag you must compare your timestamp to be lower than - 1970 years in seconds

EDIT

There's seems to be a problem in years between 1000 BC an 0 BC if you are using Y flag. The year becomes 0013 for 13 BC, so you should consider additional parsing for this range of years.

baldrs
  • 2,132
  • 25
  • 34
  • http://it.wikipedia.org/wiki/ISO_8601 here there's some guidelines but is not enough – Mindexperiment Jul 12 '13 at 14:16
  • @Mindexperiment the best solution is to limit valid format input to couple general formats, not to the whole standard – baldrs Jul 12 '13 at 14:21
  • yess but I have to find the right format... – Mindexperiment Jul 12 '13 at 14:23
  • In russian version of the wikipedia article you mentioned there's a table with format examples covered by the standard – baldrs Jul 12 '13 at 14:25
  • I just read on the duplicate answer that the DateTime class manage every dates.. I take a look – Mindexperiment Jul 12 '13 at 14:35
  • It failed to parse date like `20321421.12.13` and it's limit lies somewhere < 100000 years AC – baldrs Jul 12 '13 at 14:38
  • 'The date and time information is internally stored as a 64-bit number so all conceivably useful dates (including negative years) are supported. The range is from about 292 billion years in the past to the same in the future.' the manual say "from about 292 billion years" – Mindexperiment Jul 12 '13 at 14:43
  • try `new DateTime('1431332.12.12');` and you'll get parse error – baldrs Jul 12 '13 at 14:45