[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"detail-sidebar-cat-0-en-105":3,"doc-seo-291429-105":59,"doc-detail-291429-en":130},{"code":4,"msg":5,"data":6},0,"success",[7,13,18,23,28,33,38,43,48,51,55],{"id":8,"doc_module":4,"doc_module_name":9,"category_name":10,"show_sort_weight":11,"slug":12},1,"Document","Story & Novel",90,"story-novel",{"id":14,"doc_module":4,"doc_module_name":9,"category_name":15,"show_sort_weight":16,"slug":17},2,"Literature",80,"literature",{"id":19,"doc_module":4,"doc_module_name":9,"category_name":20,"show_sort_weight":21,"slug":22},4,"Exam",70,"exam",{"id":24,"doc_module":4,"doc_module_name":9,"category_name":25,"show_sort_weight":26,"slug":27},5,"Comic",60,"comic",{"id":29,"doc_module":4,"doc_module_name":9,"category_name":30,"show_sort_weight":31,"slug":32},6,"Technology",50,"technology",{"id":34,"doc_module":4,"doc_module_name":9,"category_name":35,"show_sort_weight":36,"slug":37},7,"Healthcare",40,"healthcare",{"id":39,"doc_module":4,"doc_module_name":9,"category_name":40,"show_sort_weight":41,"slug":42},8,"Research & Report",30,"research-report",{"id":44,"doc_module":4,"doc_module_name":9,"category_name":45,"show_sort_weight":46,"slug":47},9,"Religion & Spirituality",20,"religion-spirituality",{"id":46,"doc_module":4,"doc_module_name":9,"category_name":49,"show_sort_weight":46,"slug":50},"World Cup","world-cup",{"id":52,"doc_module":4,"doc_module_name":9,"category_name":53,"show_sort_weight":52,"slug":54},10,"Lifestyle","lifestyle",{"id":56,"doc_module":4,"doc_module_name":9,"category_name":57,"show_sort_weight":24,"slug":58},19,"General","general",{"code":4,"msg":60,"data":61},"ok",{"site_id":62,"language":63,"slug":64,"title":65,"keywords":66,"description":67,"schema_data":68,"social_meta":123,"head_meta":125,"extra_data":127,"updated_unix":129},105,"en","24-working-with-dates-and-times-overview-converting-and-displaying-stata-datetime-values","24 Working with dates and times - Overview - Converting and displaying Stata datetime values","","Working with dates and times in Stata covers how to input datetime information as strings, convert them into Stata’s internal numeric %t values, and apply display formats so readable dates and times appear instead of integers. It explains the millisecond-based encoding anchored at 01jan1960, including variants that ignore or account for leap seconds. The section also introduces pure time values, how arithmetic with date/time values works, and the main %t variable and %t format types for clocks, dates, weeks, months, quarters, half-years, and years.",{"@graph":69,"@context":122},[70,84,105],{"@type":71,"itemListElement":72},"BreadcrumbList",[73,77,79,82],{"item":74,"name":75,"@type":76,"position":8},"https://docshare.wps.com","Home","ListItem",{"item":78,"name":9,"@type":76,"position":14},"https://docshare.wps.com/document/",{"item":80,"name":30,"@type":76,"position":81},"https://docshare.wps.com/document/technology/",3,{"item":83,"name":65,"@type":76,"position":19},"https://docshare.wps.com/document/24-working-with-dates-and-times-overview-converting-and-displaying-stata-datetime-values/291429/",{"url":83,"name":65,"@type":85,"image":86,"author":91,"headline":65,"publisher":94,"fileFormat":97,"inLanguage":63,"description":67,"dateModified":98,"datePublished":99,"encodingFormat":97,"isAccessibleForFree":100,"interactionStatistic":101},"DigitalDocument",{"url":87,"@type":88,"width":89,"height":90},"https://docshare.wps.com/thumbnails/24-working-with-dates-and-times-overview-converting-and-displaying-stata-datetime-values/291429.png","ImageObject",300,407,{"name":92,"@type":93},"Mason","Person",{"url":74,"name":95,"@type":96},"DocShare","Organization","application/pdf","2026-10-08","2026-09-17",true,{"@type":102,"interactionType":103,"userInteractionCount":24},"InteractionCounter",{"@type":104},"ViewAction",{"@type":106,"mainEntity":107},"FAQPage",[108,114,118],{"name":109,"@type":110,"acceptedAnswer":111},"Why are datetime and date/time inputs best read as strings in Stata?","Question",{"text":112,"@type":113},"Stata recommends reading dates and times as strings, then using string-to-numeric conversion functions to create the appropriate %t numeric values.","Answer",{"name":115,"@type":110,"acceptedAnswer":116},"How does Stata encode datetime values internally?",{"text":117,"@type":113},"Stata stores dates, times, and datetimes as integers based on the number of milliseconds since the first millisecond of 01jan1960, with %tc ignoring leap seconds and %tC accounting for leap seconds.",{"name":119,"@type":110,"acceptedAnswer":120},"What are the differences among key %t variable types like %tc, %tC, and %td?",{"text":121,"@type":113},"%tc and %tC store datetime values in milliseconds since 01jan1960 (differing by leap-second handling), while %td stores calendar dates where unit changes represent entire days rather than milliseconds.","https://schema.org",{"og:url":83,"og:type":124,"og:title":65,"og:site_name":95,"og:description":67},"article",{"robots":126,"canonical":83},"index,follow",{"doc_id":128,"site_id":62},291429,1790462869,{"code":4,"msg":5,"data":131},{"doc_id":128,"user_id":132,"nickname":92,"user_avatar":133,"doc_module":4,"category_id":29,"category_name":30,"doc_title":65,"doc_description":67,"doc_content":134,"file_id":135,"file_url":136,"file_type":137,"file_size":138,"view_count":24,"is_deleted":4,"is_public":8,"is_downloadable":8,"audit_status":8,"page_count":39,"language":139,"language_code":63,"site_id":62,"html_lang":63,"table_of_contents":140,"faqs":141,"seo_title":142,"seo_description":67,"update_tm":143,"read_time":46},5909887256941,"https://ap-avatar.wpscdn.com/davatar_9964176cb1d06d4a9deccf72a44ae3dc","24 Working with dates and times  \nContents  \n24.1 Overview  \n24.2 Inputting dates and times  \n24.3 Displaying dates and times  \n24.4 Typing dates and times (datetime literals)  \n24.5 Extracting components of dates and times  \n24.6 Converting between date and time values  \n24.7 Business dates and calendars  \n24.8 References  \n24.1 Overview  \nFull documentation on Stata's date and time capabilities—including documentation on relevant functions and display formats—can be found in [D] datetime.  \nStata can work with dates such as 21nov2006, with times such as 13:42:02.213, and with dates and times such as 21nov2006 13:42:02.213 . You can write these dates and times however you wish, such as 11/21/2006, November 21, 2006, and 1:42 p.m.  \nStata stores dates, times, and dates and times as integers such as 􀀀4,102, 0, 82, 4,227, and 1,479,735,745,213 . It works like this:  \n1. You begin with the datetime variables in your data however they are recorded, such as 21nov2006 or 11/21/2006 or November 21, 2006, or 13:42:02.213 or 1:42 p.m. The original values are usually best stored in string variables.  \n2. Using functions we will describe below, you translate the original into the integers that Stata understands and store those values in a new variable.  \n3. You specify the appropriate display format for the new variable so that, rather than displaying as the integer values that they are, they display in a way you can read them such as 21nov2006 or 11/21/2006 or November 21, 2006, or 13:42:02.213 or 1:42 p.m.  \nThe numeric encoding that Stata uses is centered on the ﬁrst millisecond of 01jan1960, that is,  \n01jan1960 00:00:00.000 . That datetime is assigned integer value 0 . Integer value 1 is the millisecond after that: 01jan1960 00:00:00.001 .  \nInteger value 􀀀1 is the millisecond before that: 31dec1959 23:59:59.999 .  \nBy that logic, 21nov2006 13:42:02.213 is integer value 1,479,735,722,213 or, at least, it is if we ignore the leap seconds that have been inserted to keep clocks in alignment with astronomical observation. If we account for leap seconds, 21nov2006 13:42:02.213 would be 23 seconds later, namely, 1,479,735,745,213 . Stata can work either way.  \nObtaining the number of milliseconds associated with a datetime is easy because Stata provides functions that translate things like 21nov2006 13:42:02.213 (written however you wish) to 1,479,735,722,213 or 1,479,735,745,213 .  \nJust remember, Stata records datetime values as the number of milliseconds since the ﬁrst millisecond of 01jan1960 .  \nStata records pure time values (clock times independent of date) the same way. Rather than thinking of the numeric value as the number of milliseconds since 01jan1960, however, think of it as the number of milliseconds since the beginning of the day. For instance, at 2 p.m. every day, the airplane takes off from Houston for London. The numeric value [associated with 2 p.m. is](associated with 2 p.m. is) 50,400,000 because there are that many milliseconds between the beginning of the day (00:00:00.000) and 2 p.m.  \nThe advantage of thinking this way is that you can add dates and times. What is the datetime value for when the plane takes off on 21nov2006? Well, 21nov2006 00:00:00.000 is 1,479,686,400,000 (ignoring leap seconds), and 1,479,686,400,000 + 50,400,000 is 1,479,736,800,000 .  \nSubtracting datetime values is useful, too. How many hours are there between 21jan1952 7:23 a.m. and 21nov2006 3:14 p.m.? Answer: (1,479,741,240,000 􀀀 (􀀀250,706,220,000))=3,600,000 = 480,679 . 85 hours.  \nVariables that record the number of milliseconds since 01jan1960 and ignore leap seconds are called %tc variables.  \nVariables that record the number of milliseconds since 01jan1960 and account for leap seconds are called %tC variables.  \nStata has seven other kinds of %t variables.  \nIn many applications, calendar dates by themselves are sufﬁcient. The applicant was hired on 15jan2006, for instance. You could use a %tc variable to record that value, assigning","cbCaihfARzHsy3qH","https://ap.wps.com/l/cbCaihfARzHsy3qH","pdf",126639,"English","# 24 Working with dates and times\n## 24.1 Overview\n## 24.2 Inputting dates and times\n## 24.3 Displaying dates and times\n## 24.4 Typing dates and times (datetime literals)\n## 24.5 Extracting components of dates and times\n## 24.6 Converting between date and time values\n## 24.7 Business dates and calendars\n## 24.8 References","[{\"question\":\"Why are datetime and date/time inputs best read as strings in Stata?\",\"answer\":\"Stata recommends reading dates and times as strings, then using string-to-numeric conversion functions to create the appropriate %t numeric values.\"},{\"question\":\"How does Stata encode datetime values internally?\",\"answer\":\"Stata stores dates, times, and datetimes as integers based on the number of milliseconds since the first millisecond of 01jan1960, with %tc ignoring leap seconds and %tC accounting for leap seconds.\"},{\"question\":\"What are the differences among key %t variable types like %tc, %tC, and %td?\",\"answer\":\"%tc and %tC store datetime values in milliseconds since 01jan1960 (differing by leap-second handling), while %td stores calendar dates where unit changes represent entire days rather than milliseconds.\"}]","24 Working with dates and times - Overview - Converting and displaying Stata datetime values | PDF",1789645265]