2

is there anyone there who can tell me what type of a date format is this '1110620'? And how can I convert this to a 'yyyy-MM-dd' format. Any help is highly appreciated. Thanks!

abatishchev
  • 98,240
  • 88
  • 296
  • 433
KG Sosa
  • 21,565
  • 6
  • 26
  • 27
  • 3
    Obviously it is the 20th of June, AD 111 – H H Nov 29 '11 at 08:12
  • Are you sure that's not `110620`? – Marco Nov 29 '11 at 08:12
  • 5
    It would help immensely if you already had some examples on both sides - for instance, did you obtain this `1110620` value today, and is it meant to represent today's date? – Damien_The_Unbeliever Nov 29 '11 at 08:15
  • 1
    Reliably determining the format of data based on one sample and no further information is generally not possible, and basically the same problem as [detecting the encoding of a text(file)](http://stackoverflow.com/a/90956/21567). – Christian.K Nov 29 '11 at 08:22
  • Does anyone know what today is in Captain Kirks "stardate"? Rounding allowed. – H H Nov 29 '11 at 08:26
  • @HenkHolterman: That would be [64374.2](http://trekguide.com/Stardates.htm). But only for Kirk's timeline. They have to be calculated differently for the NG stuff. Anyway it looks like "startdate" also includes time. ;-) – Christian.K Nov 29 '11 at 08:29
  • Can you post an example where you know both the number and the date it represents? – CodesInChaos Nov 29 '11 at 19:02

4 Answers4

2
DateTime d;
if (DateTime.TryParse("1110620", CultureInfo.InvariantCulture, DateTimeStyles.None, out d))
    string r = d.ToString("yyyy-MM-dd");
else
    throw new Exception();
abatishchev
  • 98,240
  • 88
  • 296
  • 433
1

This should work:

string dt = "1110620";
DateTime dt = DateTime.ParseExact(dt, "yyyMMdd", 
                                  CultureInfo.CultureInvariant);

or you can try (not elegant but works)

        int start = dt.Length - 4;
        DateTime d = new DateTime(
            int.Parse(dt.Substring(0, start)),
            int.Parse(dt.Substring(start, 2)),
            int.Parse(dt.Substring(2 + start, 2)));
Marco
  • 56,740
  • 14
  • 129
  • 152
  • @Henk: Have you any other, non-joke ideas what format is represented? – abatishchev Nov 29 '11 at 08:25
  • @HenkHolterman: I thought OP was wrong with date... but he confirmed it was correct. I don't know if my answer is what OP is searching for... really, don't know. :) – Marco Nov 29 '11 at 08:26
  • @abatishchev : if it's a Julian daynumber it means 17 Sep 1673. – H H Nov 29 '11 at 08:31
0

The above format seems to be - yyyMMdd. You can write c# method to convert it accordingly. Refer MSDN for more details.

Nitin Rastogi
  • 1,446
  • 16
  • 30
0

My guess is that the first 3 digits are an extension of a two digit year. Where 100 corresponds to the year 2000.

So the format was originally yyMMdd and or perhaps (year-1900)*10000+month*100+day which extends logically to years after 2000 by prefixing a 1. This also preserves integer sorting order.

So to parse it you could:

day=input%100;
month=input/100%100;
year=input/10000+1900;

With this formula 1110620 corresponds to 2011-06-20

But unless you explain what your example should mean, this is just speculation.


My first guess was that it might be days since a certain date, but this would put the origin at around 1000BC, which is unlikely.

CodesInChaos
  • 106,488
  • 23
  • 218
  • 262