{"id":205,"date":"2013-05-29T15:38:58","date_gmt":"2013-05-29T15:38:58","guid":{"rendered":"http:\/\/localhost:8080\/spss-tricks_00\/?p=205"},"modified":"2016-05-23T06:06:56","modified_gmt":"2016-05-23T06:06:56","slug":"spss-date-variables-basics","status":"publish","type":"post","link":"https:\/\/www.spss-tutorials.com\/spss-date-variables-basics\/","title":{"rendered":"SPSS Date Variables Basics"},"content":{"rendered":"<!--body-->\n\n<p>SPSS date variables may seem a bit puzzling at first. However, getting things done fast and accurately with SPSS date variables is not hard at all if you understand some basics. This tutorial will walk you through. You can follow along by downloading and opening <a href=\"https:\/\/www.spss-tutorials.com\/downloads\/hospital.sav\">hospital.sav<\/a>.<\/p>\n\n<span class='img w840 smt smb'>\n\t<img src='https:\/\/spss-tutorials.com\/img\/spss-date-variable-in-data-view.png' alt='SPSS Date Variable in Data View'>\n<\/span>\n\n<h2>SPSS Date Variables - What Are They?<\/h2>\n\n<p>First of all, SPSS date variables are <a href=\"https:\/\/www.spss-tutorials.com\/spss-numeric-variables-basics\/\">numeric variables<\/a>; their actual values are just numbers. More precisely, the numbers they hold are the <strong>number of seconds between the year 1582 and the start (midnight) of a given date<\/strong>. Realizing that it's these underlying values that date calculations act upon renders SPSS date logic straightforward.<br>\nSecond, these huge numbers are usually <strong>shown as normal dates<\/strong> by setting their <a href=\"https:\/\/www.spss-tutorials.com\/spss-variable-types-and-formats\/#variable-formats\">format<\/a> to one of SPSS' main date formats. We'll outline some of those in the table below.<\/p>\n\n<h2 id='date-format'>SPSS Date Formats<\/h2>\n\n<p>As we just mentioned, SPSS date values are always numbers of seconds. You can <strong>choose several formats for displaying them<\/strong> as actual dates. Some main options are given in the table below.<\/p>\n\n<table class='data w40'>\n<tr><th>Variable Type<\/th><th>Format family<\/th><th>Format (example)<\/th><th>Shown as<\/th><\/tr>\n<tr><td>Numeric<\/td><td>Date<\/td><td>Date11<\/td><td>19-jan-2013<\/td><\/tr>\n<tr><td>Numeric<\/td><td>Edate (= European date)<\/td><td>Edate10<\/td><td>19.01.2013<\/td><\/tr>\n<tr><td>Numeric<\/td><td>Adate (= American date)<\/td><td>Adate10<\/td><td>01\/19\/2013<\/td><\/tr>\n<tr><td>Numeric<\/td><td>Sdate (= Sortable date)<\/td><td>Sdate10<\/td><td>2013\/01\/19<\/td><\/tr>\n<\/table>\n\n<p>As suggested by this table, we recommend that you always display years as 4 digits instead of 2.<\/p>\n\n\n<h2>SPSS Date Variables - Example<\/h2>\n\n<p>The aforementioned points may sound rather abstract so let's demonstrate them on our data. It contains one proper date variable, entry_date. We'll take a look at its actual values by giving it an f format. Running the following line of <a href=\"https:\/\/www.spss-tutorials.com\/spss-syntax\/ \">syntax<\/a> does just that.\n<span class='code'>formats entry_date(f1).<\/span>\n<\/p>\n\n<span class='img w360'>\n\t<img src='https:\/\/spss-tutorials.com\/img\/spss-date-variable-in-f-format.png' alt='SPSS Date Variabe in F Format'>\n<\/span>\n\n<p>\nThe date values now look very differently in <a href=\"https:\/\/www.spss-tutorials.com\/spss-data-editor-window\/#spss-data-view\">data view<\/a>. However, they are still the exact same values that we had a few seconds ago; they're just displayed differently. We'll now show them as dates by running\n<span class='code'>formats entry_date(sdate10).<\/span>\nAfter doing so, the actual date values look like date values again. Again, keep in mind that actual values still haven't changed in any way.<\/p>\n\n<h2>SPSS Date Calculations<\/h2>\n\n<p>So why bother about the huge numbers that underlie SPSS date values? The reason is that its these values that <strong>SPSS <a href=\"https:\/\/www.spss-tutorials.com\/spss-date-variables-tutorial\/#date-functions\">date functions<\/a><\/strong> act upon.<br>\nWhen we understand that date values are really numbers of seconds, it becomes <strong>very easy to add, say, one day to date values<\/strong>. Note that one day is 60 (seconds) * 60 (minutes) * 24 (hours) = 86400 seconds. Now watch what happens when we simply add 86400 to our date variable by running the syntax below.<\/p>\n\n<div class='code'><strong>*Add one day (= 86400 seconds) to date variable.<br><\/strong><br>compute entry_date = entry_date + 86400.<br>exe.<\/div><!--class='code'-->\n<p>Indeed, exactly one day has been added to all values. However, adding a month is more complicated because different months hold different numbers of days.<br>\nFor such cases SPSS has some <strong>specialized date functions<\/strong> that render such operations a piece of cake. The next tutorial will walk you through the most important ones.<\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>SPSS date variables are not hard to work with if you understand some basics. This tutorial walks you through them by showing some simple data examples.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[80],"tags":[],"class_list":["post-205","post","type-post","status-publish","format-standard","hentry","category-spss-date-calculations"],"_links":{"self":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/posts\/205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/comments?post=205"}],"version-history":[{"count":0,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/posts\/205\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/media?parent=205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/categories?post=205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spss-tutorials.com\/wp-json\/wp\/v2\/tags?post=205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}