CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2001
    Posts
    342

    Need faster replacement for COleDateTime::Format()

    I have an app which manipulates a lot of dates (reading from a database).

    It uses the Format() member function of COleDateTime extensively.

    During a recent profiling session, it became apparent that a large amount of my app's time is spent in the Format() function.

    Here's how I'm using it:
    Code:
    COleDateTime date1 = x.Format("%m/%d/%Y");
    Simple, yes. But very expensive in terms of CPU time.

    Does anyone have a faster way to do this?

  2. #2
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    try this:

    std::stringstream x;
    x << date1.GetMonth() << "/" << date1.GetDay() << "/" << date1.GetYear();

  3. #3
    Join Date
    Feb 2001
    Posts
    342

    Oops, I realized I wrote my post wrong

    should have been:

    I have an app which manipulates a lot of dates (reading from a database).

    It uses the Format() member function of COleDateTime extensively.

    During a recent profiling session, it became apparent that a large amount of my app's time is spent in the Format() function.

    Here's how I'm using it:

    Code:
    CString date1 = x.Format("%m/%d/%Y");
    (x is a COleDateTime variable)

    Simple, yes. But very expensive in terms of CPU time.

    Does anyone have a faster way to do this?

  4. #4
    Join Date
    Dec 2001
    Location
    Ontario, Canada
    Posts
    2,236
    Why not have the provider convert it to a string for you? When binding you accessor just change the type to DBTYPE_STR.

  5. #5
    Join Date
    Feb 2001
    Posts
    342

    I probably didn't explain correctly

    For this discussion, let's forget that the values are in a database.

    I still have to do a lot of format()s outside of the database access stuff.

    And the OLE DB library I use requires me to read dates as dates, not as strings.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured