File Exchange

image thumbnail

Daylight Savings Time

version 1.0.0.0 (1.6 KB) by Nate
Checks if a date is during USA daylight savings time

1 Download

Updated 20 Jul 2011

View License

Function takes a date as a string in 'mm/dd/yyyy' format and outputs a
logical, true if the date is during daylight savings time for that year. See
definition of daylight savings time in the USA

Cite As

Nate (2021). Daylight Savings Time (https://www.mathworks.com/matlabcentral/fileexchange/32263-daylight-savings-time), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

K E

Can alter to accept Matlab time as input as follows,

if ~isstr(timeIn)
Date = datestr(timeIn, 'mm/DD/YYYY');
else
Date = timeIn;
end

Mark Morehead

This only works for 2007 and onward. The date definition changed in 2007 by President Bush Jr. It would be helpful if this allowed for input of a vector of Matlab's "datenums" instead of a text string.

Jeff Mather

Pretty much does exactly what you would want it to do.

Moeti Ncube

Nate

Hey Moeti,

This is because these dates are during USA daylight savings time. The 2011 switch occured 11/06/2011, and therefore

is_Daylight_Savings('11/06/2011') = 0 (false)
and
is_Daylight_Savings('10/31/2011') = 1
(true)

so there is no problem.
Nate

Moeti Ncube

Good idea, however something is not right...

is_Daylight_Savings('10/29/2011')
is_Daylight_Savings('10/30/2011')
is_Daylight_Savings('10/31/2011')

All return 1's

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!