2.1.8.33 str_to_date


Description

Convert a text string that represents date/time into a Julian date value, using system date time format

Syntax

double str_to_date( LPCSTR lpcsz, int nFmt = LDF_SHORT, LPCSTR lpcszCustom = NULL )

Parameters

lpcsz
[input]a date/time string
nFmt
[input] date format, same as in Origin's GUI when column type is Date, LDF_SHORT = System Short Format. See other format type LDF_* in OC_const.h file.
lpcszCustom
[input] custom format. if nFmt is LDF_OBJ_CUSTOM, then use this param as the custom date format.

Return

A no-missing double value represent a Julian date if success, else a missing value

Examples

EX1

void str_to_date_ex1()
{
    //custom format
    string strDate = "2009-4-25 17:59:59";
    double dt = str_to_date(strDate, LDF_OBJ_CUSTOM, "yyyy-MM-dd HH:mm:ss");
    
    //default format is LDF_SHORT
    string strShort = get_date_str(dt, LDF_SHORT);//OS System's short format, by default it's "M/d/yyyy" if the OS is U.S region
    double db = str_to_date(strShort);    
    if(!is_missing_value(db))
    {
        printf("%s = %g\n", strShort, db);
    }
    else
        out_str("the string is not recorgnized as a date string");

    //LDF_YYMMDD_AND_HHMMSS 
    string strYMDHMS = get_date_str(dt, LDF_YYMMDD_AND_HHMMSS);    
    db = str_to_date(strYMDHMS, LDF_YYMMDD_AND_HHMMSS);
    if ( is_missing_value(db) )
        out_str("Fail to convert string to date");
    else
	printf("%s = %g\n", strYMDHMS, db);
}

Remark

See Also

get_date_str, str_to_date_custom

Header to Include

origin.h

Reference