File Exchange

image thumbnail

Round Dates and Times

version 1.6.5 (8.04 KB) by Stephen Cobeldick
Round dates/times to the selected unit (round/floor/ceiling).


Updated 30 Nov 2020

View Version History

View License

This function rounds datetime or serial date numbers or date vectors to the nearest year, month, day, hour, minute, or second. With a choice of rounding, floor, or ceiling.

### Examples ###

Examples use the date+time described by the vector [1999,1,3,15,6,48.0568].

ans = [1999,1,3,15,6,48]

ans = [1999,1,3,15,6,48]

ans = [1999,1,3,15,7,0]

datevec(dateround([1999,1,3,15,6,48.0568],5)) % 5=='minute'
ans = [1999,1,3,15,7,0]

ans = [1999,1,3,15,6,0]

ans = [2000,1,1,0,0,0;1999,12,31,23,59,59]

Cite As

Stephen Cobeldick (2021). Round Dates and Times (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Chang hsiung

Jeff Jackson

Jeff Jackson

Jeff H

Nicely done. It is useful to have a time rounding fn to determine if times are equal within a tolerance, especially if they may have lost significant digits.

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!