PDF version (NAG web site
, 64-bit version, 64-bit version)
NAG Toolbox: nag_time_date_string_compare (x05ac)
Purpose
nag_time_date_string_compare (x05ac) compares two date/time character strings, each stored in the format returned by
nag_time_date_array_string (x05ab).
Syntax
Description
nag_time_date_string_compare (x05ac) compares two date/time character strings, and returns an integer that specifies which one is the earliest. The result is an integer returned through the function name, with meaning as follows:
- if nag_time_date_string_compare (x05ac)
, the first date/time string is earlier than the second;
- if nag_time_date_string_compare (x05ac)
, the two date/time strings are equivalent;
- if nag_time_date_string_compare (x05ac)
, the first date/time string is later than the second.
References
None.
Parameters
Compulsory Input Parameters
- 1:
– string
- 2:
– string
-
The date/time strings to be compared. These are expected be in the format returned by
nag_time_date_array_string (x05ab), although
nag_time_date_string_compare (x05ac) will still attempt to interpret the strings if they vary slightly from this format. See
Further Comments for further details.
Optional Input Parameters
None.
Output Parameters
- 1:
– int64int32nag_int scalar
The result of the function.
Error Indicators and Warnings
None.
Accuracy
Not applicable.
Further Comments
For flexibility,
nag_time_date_string_compare (x05ac) will accept various formats for the two date/time strings
ctime1 and
ctime2.
The strings do not have to be the same length. It is permissible, for example, to enter with one or both of the strings truncated to a smaller length, in which case missing fields are treated as zero.
Each character string may be of any length, but everything after character is ignored.
Each string may or may not include an alphabetic day name, such as ‘Wednesday’, at its start. These day names are ignored, and no check is made that the day name corresponds correctly to the rest of the date.
The month name may contain any number of characters provided it uniquely identifies the month, however all characters that are supplied are significant.
Fields in the character string must be separated by one or more spaces.
The case of all alphabetic characters is not significant.
Any field in a date time string that is indecipherable according to the above rules will be converted to a zero value internally. Thus two strings that are completely indecipherable will compare equal.
According to these rules, all the following date/time strings are equivalent:
- ‘Thursday 10th July 1958 12:43:17.320’
- ‘THU 10th JULY 1958 12:43:17.320’
- ‘10th Jul 1958 12:43:17.320’
Example
This example initializes two date/time strings, and compares them by a call to nag_time_date_string_compare (x05ac).
Open in the MATLAB editor:
x05ac_example
function x05ac_example
fprintf('x05ac example results\n\n');
ctime1 = 'Thu 27th April 1989 13:15:21.320 ';
ctime2 = 'Wed 26th April 1989 11:23:14.130 ';
[result] = x05ac(ctime1, ctime2);
if result<0
compare = 'is earlier than';
elseif result==0
compare = 'is the same as';
else
compare = 'is later than';
end
fprintf('%s\n%s\n%s\n',ctime1,compare,ctime2);
x05ac example results
Thu 27th April 1989 13:15:21.320
is later than
Wed 26th April 1989 11:23:14.130
PDF version (NAG web site
, 64-bit version, 64-bit version)
© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015