Databases Reporting with SQL Date and Time Functions Practice Session

Nick Manring
Nick Manring
11,369 Points

why do we have to use a capital "Y" when doing date formatting. why is it only the year that is capital. so frustrating

I'm just curious as to why this format condition is required for year. I know when I use application like Excel or other similar programs and do formatting with functions or programming, it doesn't matter. Here, you clearly ask for the capital Y in the last code challenge of this section. I was really annoyed to find this to be why I was getting it wrong over and over.

Anyway, glad I know now. Is it like this in all SQL environments?

Thanks

2 Answers

Kevin Korte
Kevin Korte
28,096 Points

Because %y would give you the two digit date, i.e. 2016 would be just 16.

You can see here: http://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_date-format

All of the options that sql gives you to format dates. It's likely that most all sql databases will use the same formatters, or at least be very similar, but always be sure to check that sql database's documents for the same version you're using to be sure.

Nick Manring
Nick Manring
11,369 Points

Ah.. interesting. Ok. I figured that would be y, yy, yyyy, or the same in caps. I thought that was pretty universal but i guess not! :)

thanks!

It is "universal", in the sense that this isn't the only language that requires this type of output to display the date in 4 digits vs. 2 digits. For example, PHP also requires using uppercase Y instead of lowercase y to display the Date(). I know this isn't entirely related, but you can see what I mean by following this link http://php.net/manual/en/function.date.php