r/datascience • • Jul 09 '19

The formatting struggle.

Post image
1.7k Upvotes

95 comments sorted by

457

u/Yojihito Jul 09 '19

ISO 8601 - YYYY-MM-DDThh:mm:ss.sTZD

Fight me!

8

u/postal__dude Jul 09 '19

Expanded Brain : System timestamp fromat

2

u/Yojihito Jul 10 '19

You can easily convert it to UNIX time, add or subtract 2 timestamps and converting back to get the time difference.

Did this 2 weeks ago to analyse request time in a HAR file.

73

u/jalagl Jul 09 '19

Came to say this. He is wrong. :)

33

u/[deleted] Jul 09 '19

You have my sword

16

u/infrequentaccismus Jul 09 '19

And my axe body spray

5

u/nickmhc Jul 09 '19

And my bow flex

4

u/RogueVector Jul 09 '19

And my footrest (proper posture is no joke).

25

u/aftersox Jul 09 '19

4

u/Amisarth Jul 09 '19

Wait that's a real subreddit?

11

u/cyran22 Jul 09 '19

The only correct way to represent dates/datetimes as strings. God bless you.

9

u/theAnalyst6 Jul 09 '19

Are you single?

10

u/Yojihito Jul 09 '19

Depends. Is your ISO 8601 in UTF8?

-1

u/remram Jul 10 '19

Also known as ASCII

1

u/Trxisj Jul 11 '19

UTF-8 is effectively a superset of ASCII, but it isn’t ASCII.

2

u/remram Jul 11 '19 edited Jul 11 '19

ISO 8601 only uses ASCII characters, so calling it UTF-8 is technically correct but misguiding. You can also call it Markdown.

4

u/[deleted] Jul 09 '19

We stand united.

2

u/WiggleBooks Jul 09 '19

Whats the T after the date? Is it just a "T" or does it represent something?

And whats TZD?

6

u/Yojihito Jul 09 '19

T:

A single point in time can be represented by concatenating a complete date expression, the letter "T" as a delimiter, and a valid time expression.

2007-04-05T14:30

TZD:

If a time zone designator is required, it follows the combined date and time.

"2007-04-05T14:30Z"

"2007-04-05T12:30-02:00"

1

u/[deleted] Jul 10 '19

But reading 'ddThh is confusing for the eye! If only there were a space there instead'

1

u/Arqwer Feb 21 '22

Microseconds from UNIX epoch

1

u/MilkyMilkerson Mar 01 '22

Year first is the only way if you want to sort a list of dates chronologically.

46

u/[deleted] Jul 09 '19

I prefer YDMYDMYY

8

u/WiggleBooks Jul 09 '19

I prefer YDMYDMYY

Today is

20009719
or
2019 07 09

2

u/iheartrms Jul 10 '19

Some men just want to watch the world burn.

19

u/decimated_napkin Jul 09 '19

unix timestamp or gtfo

2

u/_westernmagic Jul 09 '19

Which cannot represent leap seconds

3

u/cbarrick Jul 10 '19

You don't need leap seconds in Unix. It's just the number of seconds elapsed since the epoch. It's always unambiguous. You only need to consider leap seconds when converting to a format that cares.

-1

u/[deleted] Jul 09 '19

Seriously. There is only one machine readable perfectly transformable date standard and this is it.

19

u/tenbre Jul 09 '19

I can't believe you shared such a lousy date format

17

u/kominetz Jul 09 '19

You know nothing, Femi Lee.

There is ISO-8601. Anything else is irrelevant. There can be only one (correct date format).

XKCD agrees: https://xkcd.com/1179/

5

u/saurabk1 Jul 10 '19

YYYY-MM-DD

1

u/totalnotjunk Jul 14 '19

2019-07-14

Happy Cake Day!

5

u/CharlestonChewbacca Jul 10 '19

YYYY-MM-DD

Confuses no one and is good for sorting.

13

u/dudeasaurusrex Jul 09 '19

DDMMMYYYY (eg. 09JUL2019) is never ambiguous and the order of the elements is small to large.

YYYYMMDD if you need it sortable as a character string.

6

u/sitbon Jul 09 '19

We shall call this sub Date-A-Science

0

u/Khashoggis-Thumbs Jul 09 '19

Pandas will read anything in so long as the format is known. It is inconsistent and ambiguous data that requires some detective work.

5

u/postal__dude Jul 09 '19

At a performance cost for large data amount. Take the example of fread() from Data.table in R. Fast as hell but parses dates as chars. I benchmarked the process of importing via read.csv2() with date format vs fread() and seperate date parsing and the fread() was way quicker

3

u/Khashoggis-Thumbs Jul 09 '19

I also find separate date parsing in python faster than specifying a parser besides str for pd.read_csv()

1

u/JoeInOR Jul 09 '19

Datetime library definitely saved my ass a few times.

1

u/notos Jul 09 '19

Needs more jpeg

1

u/MelonFace Jul 09 '19

ITT: People who never had to deal with third party data from different time zones.

A datetime is not a datetime before you have it's time zone.

And as if that is not enough, there are some countries that turn the clock back an hour during winter.

2

u/beatemdown Jul 10 '19

This guy datetimes

2

u/most_humblest_ever Jul 11 '19

That's dumb. Now their winter is an hour longer.

1

u/[deleted] Oct 23 '19

YYYY/MM/DD is better. Numbers are typically sorted by the biggest digits first, so why don't we do the same for dates?

0

u/Proto_Ubermensch Jul 12 '19

MM-DD-YYYY

It matches the way we say it. March 15th, 2019

Who the fuck says 15th march, 2019?

2

u/postal__dude Jul 12 '19

Bro, not everybody in the world speaks English ! In French for example we say "Le 15 Mars 2019" And all French/European systems use the DD-MM-YYYY format.

0

u/Proto_Ubermensch Jul 13 '19

English is the dominant global language of business. As evidenced by the fact that we're on Reddit using english not french.

GG no RE.

0

u/mailfriend88 Jul 09 '19

A nice silent candlelight dinner with my most loved person! a perfect date!

0

u/[deleted] Jul 09 '19

[deleted]

101

u/blaze_firestormer Jul 09 '19

I even like it as YYYYMMDD.

45

u/Aesthetically Jul 09 '19

In string type this is the master date format in my opinion. Easy to parse this out and convert it to any desire format. No dashes slashes or any crap to worry about, string type, and the bigger unit always comes first for quick sorting.

23

u/jackmaney Jul 09 '19

As a bonus, you can even store it as an integer.

15

u/DuffBude Jul 09 '19

Just don't increment it..

1

u/jackmaney Jul 09 '19

Yeah, that's really about the only caveat to storing dates that way. It's easy enough to write a function or wrapper around whatever date class you're using that does the incrementing correctly.

1

u/JustNotCricket Jul 11 '19

But ... Why?

5

u/Aesthetically Jul 09 '19

And integers are lower memory right?

13

u/jackmaney Jul 09 '19

Yeah, an eight character string takes eight bytes (assuming we're not using a weird encoding like UTF-16) whereas a 32 bit integer only takes up four bytes. Also, integer comparisons are generally quicker than string comparisons.

5

u/Trxisj Jul 11 '19 edited Aug 23 '19

All programming languages, libraries, system utilities, and just about anything you’ll ever use should sort YYYY-MM-DDThh:mm:ss (and similar) exactly the same as YYYYMMDDhhmmss. All dates similar to that - which are considered ISO 8601 dates / datetimes - are naturally lexicographically sortable.

The only difference between YYYY-MM-DD and YYYYMMDD is the first is way more human-readable, which is why it should always be preferred over the un-delimited one, IMO. Code is for humans to read, not machines. I’d also say it’s much easier to parse out with the delimiters than without. If you’re ever in a situation without native ISO 8601 parsing, you’d probably not prefer looking at 20131113141341 compared to 2013-11-13T14:13:41. You can quickly glance at the latter and immediately understand it. Sure, you’ll obviously still be able to interpret the un-delimited one, but it’s going to take more time. If you’re looking at a ton of dates, that time can add up. I’ve been in debugging situations where I have to look at a bunch of files like:

20152115146121.csv
20131133141341.csv
20132513262452.csv
20142141579449.csv
20122943594418.csv
20182313179436.csv
20144163929251.csv
20191845412338.csv
20134193144619.csv
20142921594531.csv

times 1000. It’s an eye sore, especially if the task requires you to pay closer attention to the less significant digits than the more significant ones. And if the numbers are in a small font and aren’t displayed with much padding, they can even kind of mentally blend together a little.

We already have a readable, naturally sortable, standard format most technologists and systems have agreed on since 1988; why not use it?

2

u/Aesthetically Jul 11 '19

You pose great points and have convinced me the delimited version is better.

Doesn't change the fact our enterprise uses the non delimited format for fiscal dates :/

-1

u/remram Jul 10 '19

It's also the one that's not confusing, @femscie is wrong. Both MM/DD/YYYY (USA) and DD/MM/YYYY (everyone else) are used, but no one uses YYYY-DD-MM.

1

u/Aesthetically Jul 10 '19

I think I speak for the planet when we say that format blows

9

u/[deleted] Jul 09 '19 edited Apr 21 '26

[removed] — view removed comment

1

u/Aesthetically Jul 09 '19

Luckily 0 padding the month and day values is input controllable for my use cases.

2

u/[deleted] Jul 09 '19

Pig

4

u/seanjames84 Jul 09 '19

YTMND

2

u/starship-unicorn Jul 09 '19

That's an old reference

32

u/wintermute93 Jul 09 '19

Ddmmyyyy might be more intuitive to read but yyyymmdd has the not insignificant advantage of alphabetical sort = chronological sort.

29

u/Theonewhoplays Jul 09 '19

it also transitions smoothly into a timestamp:

YYYYMMDDHHMMSS

6

u/MeagoDK Jul 09 '19

And you just converted me!

0

u/[deleted] Jul 09 '19

[deleted]

8

u/[deleted] Jul 09 '19

No, it’s a weird format. Most people use the YYYY-MM-DD format as it’s what most of Asia uses. Plus it’s the easiest to read.

2

u/Eze-Wong Jul 09 '19

Biggie -> Smalls 4 lyfe

-3

u/jackmaney Jul 09 '19

Only if you would say, eg, "the ninth of July, 2019" instead of "July ninth, 2019". The latter phrasing is far more common in the US.

2

u/wintermute93 Jul 09 '19

Do you also say $5 as "dollars five"?

-2

u/jackmaney Jul 09 '19

Nope, and the vast majority of Americans wouldn't either. Your point?

3

u/wintermute93 Jul 09 '19

My point is that the way a formatted number is written (like a date/time or dollar amount) is irrelevant to the way it's pronounced, obviously.

0

u/jackmaney Jul 09 '19

Depends on whether, eg, the dollars are US, Canadian, etc. :)

0

u/wintermute93 Jul 09 '19

But that's exactly my point. The fact that how formatted numbers are written vs spoken matches up in some languages but not in others is proof that in general the two are independent of each other. Therefore, the way we say dates aloud shouldn't dictate how we write timestamps.

0

u/onahotelbed Jul 09 '19

Who cares how you say it, though?

-1

u/jackmaney Jul 09 '19

For that matter, who cares how you say it?

1

u/onahotelbed Jul 09 '19

?

The point is that the date format and the way it's spoken aloud don't really need to be the same.

-1

u/jackmaney Jul 09 '19

Yes, hence the yyyy-mm-dd format. Again, do you have a point?

1

u/onahotelbed Jul 09 '19

What in the fuck is going on. The comment to which I replied - your comment - says that dd-mm-yyyy makes no sense because it isn't aligned with what's spoken aloud. My point has been made several times, you're just an idiot.

I've literally never seen someone so worked up about something so trivial, go drink a Monster and chill out, Kyle. It's not a big deal.

-1

u/jackmaney Jul 09 '19

My point has been made several times, you're just an idiot.

Aaaand there's a report for targeted harassment.

I've literally never seen someone so worked up about something so trivial

LOL it's amusing that you think I'm "worked up" over this.

1

u/onahotelbed Jul 09 '19

"I'm not worked up, but I am reporting you, because I feel victimized"

-1

u/jackmaney Jul 09 '19

LOL And there you go again assuming that I feel a certain way. If you can read my mind, then tell me the number that I'm thinking of. Hint: It's between one and one billion.

→ More replies (0)

-1

u/insearchofansw3r Jul 09 '19

Sadly yes but the day month year format feels legit

8

u/jackmaney Jul 09 '19

...to you, perhaps. MM-dd-yyyy feels just as legit to me. However, yyyy-MM-dd is the superior date format.

1

u/insearchofansw3r Jul 09 '19

Genuine question why superior

12

u/NowanIlfideme Jul 09 '19 edited Jul 09 '19

Never ambiguous, sorting order is the string order and chronological order at the same time. You got the "most significant" numbers on the left always. You can add a timestamp at the end easily and keep this property. ISO standard 8601 is the more formal way to do this format, but for day-to-day stuff I use YYYY-MM-DD hh:mm:ss or a left substring, depending on the accuracy I need. Even in real life. Saves on ambiguity and thinking time. ;)

2

u/insearchofansw3r Jul 09 '19

Thanks fo the schooling