In Ruby:
> require 'time'
=> true
> Date.new(1401, 1, 1).saturday?
=> true
With MySQL:
SELECT dayofweek('1401-01-01')
This returns 5 which is Thursday.
In the OSX Calendar, this is also a Thursday.
What is causing this discrepancy?
I strongly suspect that one of those environments is taking into account the change from the Julian calendar to the Gregorian calendar (at various times since the 16th century depending on place).
Using my Noda Time library, we can see which is which:
using System;
using NodaTime;
class Test
{
static void Main()
{
var julian = new LocalDate(1401, 1, 1,
CalendarSystem.GetJulianCalendar(4));
var gregorian = new LocalDate(1401, 1, 1,
CalendarSystem.GetGregorianCalendar(4));
Console.WriteLine("Julian: {0}", julian.IsoDayOfWeek);
Console.WriteLine("Gregorian: {1}", gregorian.IsoDayOfWeek);
}
}
Output:
Saturday
Thursday
So it looks like Ruby has taken the transition into account, but MySQL hasn't.
The big question is: which calendar system were you interested in? (In 1401 you probably want the Julian one - but if you have dates in the 16th century or later, it becomes trickier...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With