{"id":3234,"date":"2018-04-13T23:26:47","date_gmt":"2018-04-14T04:26:47","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=3234"},"modified":"2018-04-13T23:26:47","modified_gmt":"2018-04-14T04:26:47","slug":"friday-the-13th-and-the-datetime-method","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2018\/04\/13\/friday-the-13th-and-the-datetime-method\/","title":{"rendered":"Friday the 13th and the Datetime Method"},"content":{"rendered":"\r\n<div class=\"content\"><!--introduction--><p>Today is Friday, the 13th. In many parts of the world, today is regarded as <i>unlucky<\/i>. But I want to revisit an old question: is today <i>unlikely<\/i>? What are the chances that the 13th of any month falls on a Friday? Computing the answer makes use of a new MATLAB&reg; feature, the <tt>datetime<\/tt> method.<\/p><p>I wrote about Friday the 13th in a blog post several years ago, <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2012\/07\/09\/friday-the-13th\">Cleve's Corner, Friday the 13th<\/a>. I am reusing a portion of that post today.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#8a662e83-1957-49b9-b353-7b78888749d7\">Leap Years<\/a><\/li><li><a href=\"#595d9c78-f094-4d5f-8555-63774080f83c\">Calendars<\/a><\/li><li><a href=\"#422d87b5-8847-482b-ae4b-1f15c9c8f49f\">Datenum<\/a><\/li><li><a href=\"#c2980c44-d27f-4e0d-a0fb-2a26ab739c3f\">Datetime<\/a><\/li><li><a href=\"#d2cfd6eb-8359-4ba7-adb2-40e4d2b4aa00\">Nanoseconds<\/a><\/li><li><a href=\"#8f434629-1dae-43f0-b4a6-d99db87d176e\">Proleptic<\/a><\/li><li><a href=\"#7966eae2-2725-4a96-a7ee-455bf8679cf0\">Vectorize<\/a><\/li><li><a href=\"#51eb60da-57b8-4cb4-9ded-5e9bddad4e8a\">Categorize<\/a><\/li><li><a href=\"#26f21fbf-58b5-484c-8375-a084db2dbd46\">Thanks<\/a><\/li><\/ul><\/div><h4>Leap Years<a name=\"8a662e83-1957-49b9-b353-7b78888749d7\"><\/a><\/h4><p>Leap years make our calendar a nontrivial mathematical object. The leap year rule can be implemented by this anonymous function.<\/p><pre class=\"codeinput\">    leapyear = @(y) mod(y,4)==0 &amp; mod(y,100)~=0 | mod(y,400)==0;\r\n<\/pre><p>This says that leap years happen every four years, except for the turn of centuries not divisible by 400. Try a few year numbers.<\/p><pre class=\"codeinput\">    y = [2018 2020 2000 2100]';\r\n    isleap = [y leapyear(y)]\r\n<\/pre><pre class=\"codeoutput\">isleap =\r\n        2018           0\r\n        2020           1\r\n        2000           1\r\n        2100           0\r\n<\/pre><p>So, this year is not a leap year, the next one is in 2020. The turn of the century 2000 was a leap year, but 2100 will not be.<\/p><h4>Calendars<a name=\"595d9c78-f094-4d5f-8555-63774080f83c\"><\/a><\/h4><p>The leap year rule implies that our calendar has a period of 400 years. The calendar for years 2000 to 2399 will be reused for 2400 to 2799. In a 400 year period, there are 97 leap years, 4800 months, 20871 weeks, and 146097 days. So the average number of days in a calendar year is not 365.25, but<\/p><pre class=\"codeinput\">    dpy = 365+97\/400\r\n<\/pre><pre class=\"codeoutput\">dpy =\r\n  365.2425\r\n<\/pre><p>We can compute the probability that the 13th of a month is a Friday by counting how many times that happens in 4800 months. The correct probability is then that count divided by 4800. Since 4800 is not a multiple of 7, the probability does not reduce to 1\/7.<\/p><h4>Datenum<a name=\"422d87b5-8847-482b-ae4b-1f15c9c8f49f\"><\/a><\/h4><p>For many years, computations involving dates and time have been done using a whole bunch of functions.<\/p><div><ul><li><tt>clock<\/tt><\/li><li><tt>datenum<\/tt><\/li><li><tt>datevec<\/tt><\/li><li><tt>datestr<\/tt><\/li><li><tt>dateticks<\/tt><\/li><li><tt>now<\/tt><\/li><li><tt>weekday<\/tt><\/li><\/ul><\/div><p>Those functions have served us well, but they have some significant shortcomings.  They are not particularly easy to use.  The display formatting is limited.  The floating point precision of <tt>datenum<\/tt> effectively limits the calculation of durations. There are no immediate plans to retire <tt>datenum<\/tt> and its friends, but something preferable is now available.<\/p><h4>Datetime<a name=\"c2980c44-d27f-4e0d-a0fb-2a26ab739c3f\"><\/a><\/h4><p>The <tt>datetime<\/tt> object, introduced in R2014b, combines and extends these functions into one.<\/p><div><ul><li><tt>datetime<\/tt><\/li><\/ul><\/div><p>The <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/datetime.html\">documentation for <tt>datetime<\/tt><\/a> is available online, or, from within MATLAB, with the command<\/p><pre>   doc datetime<\/pre><p>For example, here is the date and time when I am publishing this post.<\/p><pre class=\"codeinput\">    d = datetime(<span class=\"string\">'now'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">d = \r\n  datetime\r\n   13-Apr-2018 21:21:19\r\n<\/pre><p>I can specify a custom display format with<\/p><pre class=\"codeinput\">    d = datetime(d,<span class=\"string\">'Format'<\/span>,<span class=\"string\">'eeee, MMMM d, yyyy HH:mm:ss'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">d = \r\n  datetime\r\n   Friday, April 13, 2018 21:21:19\r\n<\/pre><p>The available display formats include support for an international standard, <a href=\"https:\/\/www.iso.org\/iso-8601-date-and-time-format.html\">ISO 8601<\/a>.<\/p><h4>Nanoseconds<a name=\"d2cfd6eb-8359-4ba7-adb2-40e4d2b4aa00\"><\/a><\/h4><p><tt>datetime<\/tt>'s are much more precise than <tt>datenum<\/tt>'s can ever hope to be. Try this<\/p><pre class=\"codeinput\">    hms = datetime(d,<span class=\"string\">'Format'<\/span>,<span class=\"string\">'HH:mm:ss.SSS'<\/span>)\r\n<\/pre><pre class=\"codeoutput\">hms = \r\n  datetime\r\n   21:21:19.502\r\n<\/pre><p>We see that <tt>d<\/tt> is carrying fractional seconds to at least three places beyond the decimal point.  How about nanoseconds?<\/p><pre class=\"codeinput\">    secperday = 24*60*60\r\n    nano = 1.e-9\/secperday\r\n    hms = datetime(d,<span class=\"string\">'Format'<\/span>,<span class=\"string\">'HH:mm:ss.SSSSSSSSS'<\/span>)\r\n    hmsplusnano = hms + nano\r\n<\/pre><pre class=\"codeoutput\">secperday =\r\n       86400\r\nnano =\r\n   1.1574e-14\r\nhms = \r\n  datetime\r\n   21:21:19.502000000\r\nhmsplusnano = \r\n  datetime\r\n   21:21:19.502000001\r\n<\/pre><p>A nanosecond is four orders of magnitude smaller than roundoff error of <tt>datenum<\/tt>'s in this era.  Compare<\/p><pre class=\"codeinput\">    nano\r\n    epsofdatenum = eps(datenum(d))\r\n<\/pre><pre class=\"codeoutput\">nano =\r\n   1.1574e-14\r\nepsofdatenum =\r\n   1.1642e-10\r\n<\/pre><p>I am pleased to reveal some details about the arithmetic in <tt>datetime<\/tt>. The object is using a form of quadruple precision known as <a href=\"https:\/\/blogs.mathworks.com\/cleve\/2017\/05\/22\/quadruple-precision-128-bit-floating-point-arithmetic\/\">double-double<\/a>.  In fact, the second half of the 112-bit format is stored as the imaginary part of the <tt>data<\/tt> field, as you see in the following.<\/p><pre class=\"codeinput\">    disp(struct(hmsplusnano))\r\n<\/pre><pre class=\"codeoutput\">Warning: Calling STRUCT on an object prevents the object from hiding its\r\nimplementation details and should thus be avoided. Use DISP or DISPLAY to see\r\nthe visible public details of an object. See 'help struct' for more information. \r\n                      UTCZoneID: 'UTC'\r\n              UTCLeapSecsZoneID: 'UTCLeapSeconds'\r\n                  ISO8601Format: 'uuuu-MM-dd'T'HH:mm:ss.SSS'Z''\r\n                        epochDN: 719529\r\n                   MonthsOfYear: [1&times;1 struct]\r\n                     DaysOfWeek: [1&times;1 struct]\r\n                     dateFields: [1&times;1 struct]\r\n    noConstructorParamsSupplied: [1&times;1 struct]\r\n                           data: 1.5237e+12 + 1.0000e-06i\r\n                            fmt: 'HH:mm:ss.SSSSSSSSS'\r\n                             tz: ''\r\n                     isDateOnly: 0\r\n<\/pre><h4>Proleptic<a name=\"8f434629-1dae-43f0-b4a6-d99db87d176e\"><\/a><\/h4><p>The summary description in the <tt>datetime<\/tt> documentation describes some important features of the object, which has nearly 100 methods defined.<\/p><p>\r\n<p style=\"margin-left:3ex;\">\r\n<tt>datetime<\/tt> arrays represent points in time using the proleptic\r\nISO calendar. <tt>datetime<\/tt> values have flexible display formats\r\nup to nanosecond precision and can account for time zones,\r\ndaylight saving time, and leap seconds.\r\n<\/p>\r\n<\/p><p>I had to look up the definition of \"proleptic\". In this context it means the calendar can be extended backwards in time to apply to dates even before it was adopted.<\/p><h4>Vectorize<a name=\"7966eae2-2725-4a96-a7ee-455bf8679cf0\"><\/a><\/h4><p>Let's get on with Friday the 13th.  Like most things in MATLAB <tt>datetime<\/tt> works with vectors.  The statements<\/p><pre class=\"codeinput\">    y = 2000;\r\n    m = 1:4800;\r\n    t = 13;\r\n    v = datetime(y,m,t);\r\n<\/pre><p>produce a row vector of 4800 <tt>datetime<\/tt>'s for the 13th of every month. The first few and last few are<\/p><pre class=\"codeinput\">    fprintf(<span class=\"string\">'  %s'<\/span>,v(1:4))\r\n    fprintf(<span class=\"string\">'  ...\\n'<\/span>)\r\n    fprintf(<span class=\"string\">'  %s'<\/span>,v(end-3:end))\r\n<\/pre><pre class=\"codeoutput\">  13-Jan-2000  13-Feb-2000  13-Mar-2000  13-Apr-2000  ...\r\n  13-Sep-2399  13-Oct-2399  13-Nov-2399  13-Dec-2399<\/pre><p>The statement<\/p><pre class=\"codeinput\">    w = weekday(v);\r\n<\/pre><p>produces a row vector of 4800 flints between 1 (for Sunday) and 7 (for Saturday). The first few and last few are<\/p><pre class=\"codeinput\">    fprintf(<span class=\"string\">'%3d'<\/span>,w(1:4))\r\n    fprintf(<span class=\"string\">'  ...'<\/span>)\r\n    fprintf(<span class=\"string\">'%3d'<\/span>,w(end-3:end))\r\n<\/pre><pre class=\"codeoutput\">  5  1  2  5  ...  2  4  7  2<\/pre><p>Now to get the counts of weekdays, all we need is<\/p><pre class=\"codeinput\">    c = histcounts(w)\r\n<\/pre><pre class=\"codeoutput\">c =\r\n   687   685   685   687   684   688   684\r\n<\/pre><p>There you have it.  The count for Friday, 688, is higher than for any other day of the week.  The 13th of any month is slightly more likely to fall on a Friday.<\/p><p>The probabilities are<\/p><pre class=\"codeinput\">    p = c\/4800\r\n<\/pre><pre class=\"codeoutput\">p =\r\n    0.1431    0.1427    0.1427    0.1431    0.1425    0.1433    0.1425\r\n<\/pre><p>Compare these values with their mean, <tt>1\/7 = 0.1429<\/tt>.  Four probabilities are below the mean, three are above.<\/p><h4>Categorize<a name=\"51eb60da-57b8-4cb4-9ded-5e9bddad4e8a\"><\/a><\/h4><p>Let's pair the counts with the days of the week, using a <tt>categorical<\/tt> variable, introduced in R2013b.<\/p><pre class=\"codeinput\">    c = categorical(w,1:7,{<span class=\"string\">'Sun'<\/span> <span class=\"string\">'Mon'<\/span> <span class=\"string\">'Tue'<\/span> <span class=\"string\">'Wed'<\/span> <span class=\"string\">'Thu'<\/span> <span class=\"string\">'Fri'<\/span> <span class=\"string\">'Sat'<\/span>});\r\n    summary(c)\r\n<\/pre><pre class=\"codeoutput\">     Sun      Mon      Tue      Wed      Thu      Fri      Sat \r\n     687      685      685      687      684      688      684 \r\n<\/pre><p>When we plot a histogram the appropriate labels are provided on the x-axis.  Friday the 13th is the winner.<\/p><pre class=\"codeinput\">    histogram(c)\r\n    set(gca,<span class=\"string\">'ylim'<\/span>,[680 690])\r\n    title(<span class=\"string\">'Weekday counts, 400 years'<\/span>)\r\n<\/pre><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/friday13th_blog_01.png\" alt=\"\"> <h4>Thanks<a name=\"26f21fbf-58b5-484c-8375-a084db2dbd46\"><\/a><\/h4><p>Thanks to Peter Perkins at MathWorks.  I learned a lot from him while working on this post.<\/p><script language=\"JavaScript\"> <!-- \r\n    function grabCode_bc7b3f8877f74d60b4e375268a2180cb() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='bc7b3f8877f74d60b4e375268a2180cb ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' bc7b3f8877f74d60b4e375268a2180cb';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2018 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_bc7b3f8877f74d60b4e375268a2180cb()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2018a<br><\/p><\/div><!--\r\nbc7b3f8877f74d60b4e375268a2180cb ##### SOURCE BEGIN #####\r\n%% Friday the 13th and the Datetime Method\r\n% Today is Friday, the 13th.\r\n% In many parts of the world, today is regarded as _unlucky_.\r\n% But I want to revisit an old question: is today _unlikely_?\r\n% What are the chances that the 13th of any month falls on a Friday?\r\n% Computing the answer makes use of a new MATLAB(R) feature,\r\n% the |datetime| method.\r\n%\r\n% I wrote about Friday the 13th in a blog post several years ago,\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2012\/07\/09\/friday-the-13th\r\n% Cleve's Corner, Friday the 13th>.\r\n% I am reusing a portion of that post today.\r\n\r\n%% Leap Years\r\n% Leap years make our calendar a nontrivial mathematical object.\r\n% The leap year rule can be implemented by this anonymous function.\r\n\r\n    leapyear = @(y) mod(y,4)==0 & mod(y,100)~=0 | mod(y,400)==0;\r\n\r\n%%\r\n% This says that leap years happen every four years,\r\n% except for the turn of centuries not divisible by 400.\r\n% Try a few year numbers.\r\n\r\n    y = [2018 2020 2000 2100]';\r\n    isleap = [y leapyear(y)]\r\n\r\n%% \r\n% So, this year is not a leap year, the next one is in 2020.\r\n% The turn of the century 2000 was a leap year,\r\n% but 2100 will not be.\r\n\r\n%% Calendars \r\n% The leap year rule implies that our calendar has a period of 400 years.\r\n% The calendar for years 2000 to 2399 will be reused for 2400 to 2799.\r\n% In a 400 year period, there are 97 leap years, 4800 months,\r\n% 20871 weeks, and 146097 days.\r\n% So the average number of days in a calendar year is not 365.25, but\r\n\r\n    dpy = 365+97\/400 \r\n\r\n%%\r\n% We can compute the probability that the 13th of a month is a Friday\r\n% by counting how many times that happens in 4800 months.\r\n% The correct probability is then that count divided by 4800.\r\n% Since 4800 is not a multiple of 7, the probability does not reduce\r\n% to 1\/7.\r\n\r\n%% Datenum\r\n% For many years, computations involving dates and time have been done\r\n% using a whole bunch of functions.\r\n%\r\n% * |clock|\r\n% * |datenum|\r\n% * |datevec|\r\n% * |datestr|\r\n% * |dateticks|\r\n% * |now|\r\n% * |weekday|\r\n\r\n%%\r\n% Those functions have served us well, but they have some significant\r\n% shortcomings.  They are not particularly easy to use.  The display\r\n% formatting is limited.  The floating point precision of |datenum|\r\n% effectively limits the calculation of durations.\r\n% There are no immediate plans to retire |datenum| and its friends,\r\n% but something preferable is now available. \r\n\r\n%% Datetime\r\n% The |datetime| object, introduced in R2014b, combines and extends\r\n% these functions into one.\r\n%\r\n% * |datetime|\r\n%\r\n% The <https:\/\/www.mathworks.com\/help\/matlab\/ref\/datetime.html\r\n% documentation for |datetime|> is available online, or, from within\r\n% MATLAB, with the command\r\n%\r\n%     doc datetime\r\n\r\n%%\r\n% For example, here is the date and time when I am publishing this post.\r\n\r\n    d = datetime('now')\r\n   \r\n%%\r\n% I can specify a custom display format with\r\n\r\n    d = datetime(d,'Format','eeee, MMMM d, yyyy HH:mm:ss')\r\n\r\n%%\r\n% The available display formats include support for an\r\n% international standard, \r\n% <https:\/\/www.iso.org\/iso-8601-date-and-time-format.html ISO 8601>.\r\n\r\n%% Nanoseconds\r\n% |datetime|'s are much more precise than |datenum|'s can ever hope to be.\r\n% Try this\r\n\r\n    hms = datetime(d,'Format','HH:mm:ss.SSS')\r\n    \r\n%%\r\n% We see that |d| is carrying fractional seconds to at least three\r\n% places beyond the decimal point.  How about nanoseconds?\r\n    \r\n%%\r\n    secperday = 24*60*60\r\n    nano = 1.e-9\/secperday\r\n    hms = datetime(d,'Format','HH:mm:ss.SSSSSSSSS')\r\n    hmsplusnano = hms + nano\r\n    \r\n%%\r\n% A nanosecond is four orders of magnitude smaller than roundoff\r\n% error of |datenum|'s in this era.  Compare\r\n\r\n    nano\r\n    epsofdatenum = eps(datenum(d))\r\n \r\n%%\r\n% I am pleased to reveal some details about the arithmetic in |datetime|.\r\n% The object is using a form of quadruple precision known as\r\n% <https:\/\/blogs.mathworks.com\/cleve\/2017\/05\/22\/quadruple-precision-128-bit-floating-point-arithmetic\/\r\n% double-double>.  In fact, the second half of the 112-bit format is\r\n% stored as the imaginary part of the |data| field, as you see in the\r\n% following.\r\n\r\n    disp(struct(hmsplusnano))\r\n    \r\n%% Proleptic\r\n% The summary description in the |datetime| documentation \r\n% describes some important features\r\n% of the object, which has nearly 100 methods defined.\r\n%\r\n% <html>\r\n% <p style=\"margin-left:3ex;\">\r\n% <tt>datetime<\/tt> arrays represent points in time using the proleptic\r\n% ISO calendar. <tt>datetime<\/tt> values have flexible display formats\r\n% up to nanosecond precision and can account for time zones,\r\n% daylight saving time, and leap seconds.\r\n% <\/p>\r\n% <\/html>\r\n\r\n%%\r\n% I had to look up the definition of \"proleptic\".\r\n% In this context it means the calendar can be extended backwards\r\n% in time to apply to dates even before it was adopted.\r\n\r\n%% Vectorize\r\n% Let's get on with Friday the 13th.  Like most things in MATLAB\r\n% |datetime| works with vectors.  The statements\r\n\r\n    y = 2000;\r\n    m = 1:4800;\r\n    t = 13;\r\n    v = datetime(y,m,t);\r\n    \r\n%%\r\n% produce a row vector of 4800 |datetime|'s for the 13th of every month.\r\n% The first few and last few are\r\n\r\n    fprintf('  %s',v(1:4))\r\n    fprintf('  ...\\n')\r\n    fprintf('  %s',v(end-3:end))  \r\n    \r\n%%\r\n% The statement\r\n\r\n    w = weekday(v);\r\n    \r\n%%\r\n% produces a row vector of 4800 flints between 1 (for Sunday) and 7\r\n% (for Saturday).\r\n% The first few and last few are\r\n   \r\n    fprintf('%3d',w(1:4))\r\n    fprintf('  ...')\r\n    fprintf('%3d',w(end-3:end))  \r\n    \r\n%%\r\n% Now to get the counts of weekdays, all we need is\r\n\r\n    c = histcounts(w)\r\n    \r\n%%\r\n% There you have it.  The count for Friday, 688, is higher than for\r\n% any other day of the week.  The 13th of any month is slightly more\r\n% likely to fall on a Friday.\r\n\r\n%%\r\n% The probabilities are\r\n\r\n    p = c\/4800\r\n    \r\n%%\r\n% Compare these values with their mean, |1\/7 = 0.1429|.  Four\r\n% probabilities are below the mean, three are above.\r\n\r\n%% Categorize\r\n% Let's pair the counts with the days of the week,  \r\n% using a |categorical| variable, introduced in R2013b.\r\n\r\n    c = categorical(w,1:7,{'Sun' 'Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat'});\r\n    summary(c)\r\n    \r\n%%\r\n% When we plot a histogram the appropriate labels are provided \r\n% on the x-axis.  Friday the 13th is the winner.\r\n    histogram(c)\r\n    set(gca,'ylim',[680 690])\r\n    title('Weekday counts, 400 years')\r\n    \r\n%% Thanks\r\n% Thanks to Peter Perkins at MathWorks.  I learned a lot from him\r\n% while working on this post.\r\n##### SOURCE END ##### bc7b3f8877f74d60b4e375268a2180cb\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/friday13th_blog_01.png\" onError=\"this.style.display ='none';\" \/><\/div><!--introduction--><p>Today is Friday, the 13th. In many parts of the world, today is regarded as <i>unlucky<\/i>. But I want to revisit an old question: is today <i>unlikely<\/i>? What are the chances that the 13th of any month falls on a Friday? Computing the answer makes use of a new MATLAB&reg; feature, the <tt>datetime<\/tt> method.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2018\/04\/13\/friday-the-13th-and-the-datetime-method\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,4,7],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/3234"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=3234"}],"version-history":[{"count":1,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/3234\/revisions"}],"predecessor-version":[{"id":3236,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/3234\/revisions\/3236"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=3234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=3234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=3234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}