Convert Serial Date Numbers to Datetime. A serial date number represents a calendar date as the number of days that has passed since a fixed base date. In MATLAB, serial date number 1 is January 1, 0000. Serial time can represent fractions of days beginning at midnight; for example, 6 p.m. Equals 0.75 serial.
Active4 years, 9 months ago
![Convert serial number to imei Convert serial number to imei](/uploads/1/2/5/2/125297153/525810403.jpg)
This is not so much a programming question as it is a desire for clarification to understand the way the Matlab serial date number format works. I'm referencing Matlab serial date numbers and I would like to know how to convert them into calendar dates using the simplest means possible. Many of the references out there only instruct how to work with these numbers within Matlab itself, but I want to be able to make sense of these by hand using arithmetic to derive the dates they represent without the use of Matlab (if this is even possible).
From the research I have done already, I do understand that a Matlab timestamp is essentially a count of the number of days since January 1, 0000 and that the floating point numbers appended to it further represent specific hours, minutes, etc. I'm not as clear on how these break down however. The reference information out there is not very informative nor comprehensive and I'm struggling to understand how it works.
Download Convert Serial Number To Date Matlab Free
Say I have the timestamp 735071.64930556. Could anybody provide me with a formula to be able to derive the calendar date that this represents, or guide me through the process to convert it? From a programming standpoint, my purpose for wanting to understand this is so I can eventually write a converter to be able to handle this format within the application I'm developing. For now though, I simply wish to understand how the process works.
Thanks
dsolimano7,61733 gold badges4141 silver badges5757 bronze badges
The ZuidzThe Zuidz41333 gold badges77 silver badges1818 bronze badges
2 Answers
What makes your question a little bit difficult to answer is mostly the leap year / leap second problem. If you expect date values to exist only over a limited range of values, the problem is somewhat simpler (actually I am not sure how Matlab deals with the 'lost days' when the world went from Julian to Gregorian calendars, for example - see http://en.wikipedia.org/wiki/Conversion_between_Julian_and_Gregorian_calendars for a hint of what I am talking about).
The hours-minutes-seconds part is relatively easy. When you have
You can compute:
To get the year / month / day, your best bet is to use some built in function in the language of your choice (for many examples, see http://www.epochconverter.com/epoch/daynumbers.php ), or knock yourself out and create some lookup tables. Master keystroke logger 13 09 01 serial podcast. If you have the date of the first of every month, the lookup would be fast; and from 0 CE until today, that would be only 2013 * 12 entries - not a very large table. Such a table could be created in Matlab and exported..
FlorisFloris41.1k44 gold badges5151 silver badges9494 bronze badges
Luis MendoLuis Mendo96.4k1111 gold badges5959 silver badges126126 bronze badges
Not the answer you're looking for? Browse other questions tagged matlabcalendartimestamp or ask your own question.
Active6 years, 2 months ago
I have time set up as serial dates. Each number corresponds to a day, in order, from 20100101 to 20130611. How do I convert the serial date to a date in the format month-year? Programs for scoring trap leagues under the sea. I need this because I want to plot data and need the x axis to show the date.
Thanks!
SugaKookie
SugaKookieSugaKookie51522 gold badges1414 silver badges3535 bronze badges
2 Answers
The first step is to convert your date-format into one of the standard Matlab date formats. The best format to use for plots is the 'serial date format'. The numbers itself are a bit awkward, since they represent the 'amount of time after 0/0/0000, in days', which is a huge number. Also, this date actually never existed, making it really weird when you want to work with dates that are BC.
However, the conversion is easy, since your format also counts the days, but you count after 31st of December, 2009. You can convert this using
You then plot your data using
and you let Matlab add the date-ticks automatically by calling
The problem is, the ticks do not update after zooming in. You can either call
again, after each zooming or panning, or you download
datetickzoom
from the Matlab file exchange. It takes the same arguments as datetick, but it hooks into the zoom function and updates the ticks automatically.Edit:
Sometimes, the dateticks are not spaced in any sensible way, then you can either try to zoom in and out a little until it snaps to something good, or you have to set the ticks manually:
![Matlab Matlab](/uploads/1/2/5/2/125297153/138666370.jpg)
You might have to modify the
tick_locations = datenum(2012,[1:12],1)
a bit to get the ticks that you want. For instance, you can useto get every second month between Jan 2012 and Jan 2013.
Martin J.H.Martin J.H.
Mohsen NosratiniaMohsen NosratiniaSerial Date Number Matlab
9,49711 gold badge2121 silver badges4848 bronze badges