function [ date ] = StringToDate( dateString )
%STRINGTODATE Converts string to date
%   Converts string to date using local settings

%Extract the local Windows time separator, date separator, time format, 
%short date format and long date format from the registry.
timeSep = winqueryreg('HKEY_CURRENT_USER', 'Control Panel\International', 'sTime');
dateSep = winqueryreg('HKEY_CURRENT_USER', 'Control Panel\International', 'sDate');
timeFormat = winqueryreg('HKEY_CURRENT_USER', 'Control Panel\International', 'sTimeFormat');
shortDateFormat = winqueryreg('HKEY_CURRENT_USER', 'Control Panel\International', 'sShortDate');
longDateFormat = winqueryreg('HKEY_CURRENT_USER', 'Control Panel\International', 'sLongDate');

%Convert the formats specifiers to match those of MATLAB
mlTimeFormat = upper(strrep(timeFormat, 'tt', 'AM'));
mlTimeFormat = regexprep(mlTimeFormat, 'H+', 'HH');

mlShortDateFormat = regexprep(lower(shortDateFormat), '(?<!d)d(?!d)', 'dd');
mlShortDateFormat = regexprep(mlShortDateFormat, '(?<!m)m(?!m)', 'mm');

mlLongDateFormat = regexprep(lower(longDateFormat), '(?<!d)d(?!d)', 'dd');
mlLongDateFormat = regexprep(mlLongDateFormat, '(?<!m)m(?!m)', 'mm');

%Convert given string to date.
mlLocalFormat = '';
if ~isempty(strfind(dateString, dateSep))
	mlLocalFormat = mlShortDateFormat;
end
if ~isempty(strfind(dateString, timeSep))
	mlLocalFormat = [mlLocalFormat mlTimeFormat];
end

date = datenum(dateString, mlLocalFormat);