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!
-
3Obviously 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
-
5It 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
-
1Reliably 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 Answers
DateTime d;
if (DateTime.TryParse("1110620", CultureInfo.InvariantCulture, DateTimeStyles.None, out d))
string r = d.ToString("yyyy-MM-dd");
else
throw new Exception();

- 98,240
- 88
- 296
- 433
-
-
But why the assumption of InvariantCulture? You should loop through all cultures. – H H Nov 29 '11 at 08:36
-
@Henk: What for? I'm sure there is no culture that will be able to parse it if invariant will be not. – abatishchev Nov 29 '11 at 09:03
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)));

- 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
-
The above format seems to be - yyyMMdd. You can write c# method to convert it accordingly. Refer MSDN for more details.

- 1,446
- 16
- 30
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.

- 106,488
- 23
- 218
- 262