现在有一个CString 类型 ctsr = "20050302184623" 为日期
我本想转换为__int64
__int64 i = _ttoi64((LPCTSTR)cstr);
但是老师说不行,因为日期比较是可以实现的,说了一个函数
VarDateFromStr
请问具体如何实现以及比较

解决方案 »

  1.   

    HRESULT VarDateFromStr( 
      OLECHAR *  strIn,         
      LCID  lcid,          
      unsigned long  dwFlags, 
      DATE *  pdateOut  
    );
    Parameters
    strIn 
    [in] The value to coerce. 
    lcid 
    [in] For conversions from string and VT_DISPATCH input, the LCID to use for the conversion. For a list of LCIDs, see Supporting Multiple National Languages and Exposing ActiveX Objects. 
    dwFlags 
    [in] One or more of the following flags: Flag Description 
    LOCALE_NOUSEROVERRIDE Uses the system default locale settings, rather than custom locale settings. 
    VAR_CALENDAR_HJRI If set then the Hijri calendar is used. Otherwise the calendar sent in the control panel is used. 
    VAR_DATEVALUEONLY Omits the time portion of a VT_DATE and returns only the date. Applies to conversions to or from dates. Not used for VariantChangeType and VariantChangeTypeEx. 
    VAR_TIMEVALUEONLY Omits the date portion of a VT_DATE and returns only the time. Applies to conversions to or from dates. Not used for VariantChangeType and VariantChangeTypeEx. pdateOut 
    [out] Points to the coerced value. For input dates with the year between 194707 and 206607 (inclusive), VarDateFromStr will truncate the output value and generate a valid date, with the year in the range from 0 through 9999. In this case, the function returns S_OK. 
    另外你们老师绝对有问题,简单的问题搞复杂,何必呢?????
      

  2.   

    仅仅比较日起前后的话似乎转换到__int64没有什么不可以,除非考虑到溢出,不过似乎没有什么意义,__int64的范围够大了VarDateFromStr是OLE方面的东西,麻烦……
      

  3.   

    日期转到__int64是有标准的,分为两部份(__int32),一个是存储从17??年(忘了)到当前的总天数.
    一个某日(也忘了)到当前的秒数
    所以__int64存日期只有200多年,具体可参考SQL标准,MSSQL帮助中也有.你们老师是对的,不过明显是态度不好.^_^PS:幸亏DATETIME取值标准是美国人定的,200年就够用了,要是让中国人来定没准要用到__int512.哈哈
      

  4.   

    roscoe(草上飞) 你的语言真是深入浅出,不过看不懂
      

  5.   

    胡说八道,__int64就是M$为了自己的VC++实现的额外的超逾标准的东西,怎么可能针对这种超越了标准的东西还有标准?而且你的说法自身也有矛盾。这种东西只要直接比较就可以了,根本用不着什么OLE,简单的才是最实用的
      

  6.   

    CTimeSpan可以比较两个日期
    http://sourceoflife.blogchina.com/1847677.html