DATEPART

版本 1.0.0.0 (2.1 KB) 作者: Ian Howat
Extract decimal yr/month/day/hr/min/sec from a datenum. More versatile than datevec.
1.9K 次下载
更新时间 2007/8/6

查看许可证

X = DATEPART(DATE,'part') returns the date 'part' (year, month,day, hour, minute or second) of the datenum date with the decimal equivalent of the trailing date parts in the units of 'part'. DATE can be scalar, vector or array and X will be of the some size and shape.

[X1,X2,...] = DATEPART(DATE,'part1','part2',...) returns each decimal value corresponding to each part input argument.

Acceptable string specifiers for 'part' are:
Year: 'year','yr','years','yrs'
Month: 'month','mn','months','mns'
Day: 'day','days'
Hour: 'hour','hours','hr','hrs'
Minute: 'minutes','minutes','min','mins'
Second: 'second','seconds','sec','secs'

Examples:
>> A = datenum('14-Jul-2007 15:05:12')
>> datepart(A,'min')
ans =
5.2000
>> floor(datepart(A,'min'))
ans =
5
>> format bank
>> datepart(A,'year')
ans =
2007.53
>> [day,yr] = datepart(A,'day','year')
day =
14.63
yr =
2007.53

引用格式

Ian Howat (2024). DATEPART (https://www.mathworks.com/matlabcentral/fileexchange/15585-datepart), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2006a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.0.0.0

Fixed error in seconds reporting.