Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. CString to CTime

CString to CTime

Scheduled Pinned Locked Moved C / C++ / MFC
jsontutorialquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jimmy Ehrnstrom
    wrote on last edited by
    #1

    Could anyone tell me if there's an easy way to convert date/time from CString to CTime? I would, for example, like to convert the string "2001-07-26 14:37:00" to a CTime object. I could do this using string operations to parse out the year, month, etc.. This, however, does not feel like a good solution since it's not very flexible. I would have to include several if-statements in the parsing to be able to handle dates on other formats, like "2001-07-26", "2001-07-26T14:37", etc. What would make me very happy is if there's a way to use formatting string to specify the format of the input. Like when I convert a CTime object to a CString using Format() with formatting codes like %Y, %m, etc. Maybe somebody has written a class, derived from CTime, that could handle this? Jimmy Ehrnström

    D N 2 Replies Last reply
    0
    • J Jimmy Ehrnstrom

      Could anyone tell me if there's an easy way to convert date/time from CString to CTime? I would, for example, like to convert the string "2001-07-26 14:37:00" to a CTime object. I could do this using string operations to parse out the year, month, etc.. This, however, does not feel like a good solution since it's not very flexible. I would have to include several if-statements in the parsing to be able to handle dates on other formats, like "2001-07-26", "2001-07-26T14:37", etc. What would make me very happy is if there's a way to use formatting string to specify the format of the input. Like when I convert a CTime object to a CString using Format() with formatting codes like %Y, %m, etc. Maybe somebody has written a class, derived from CTime, that could handle this? Jimmy Ehrnström

      D Offline
      D Offline
      Doug Garno
      wrote on last edited by
      #2

      You can use COleDateTime::ParseDateTime( string ) to convert the string into the underlying DATE object. If you don't like to use COleDateTime objects and need the CTime object, you would have to convert between the two. Create a tm structure and populate the structure from the COleDateTime object and then using mktime( tm ) assign the result to the CTime object.

      1 Reply Last reply
      0
      • J Jimmy Ehrnstrom

        Could anyone tell me if there's an easy way to convert date/time from CString to CTime? I would, for example, like to convert the string "2001-07-26 14:37:00" to a CTime object. I could do this using string operations to parse out the year, month, etc.. This, however, does not feel like a good solution since it's not very flexible. I would have to include several if-statements in the parsing to be able to handle dates on other formats, like "2001-07-26", "2001-07-26T14:37", etc. What would make me very happy is if there's a way to use formatting string to specify the format of the input. Like when I convert a CTime object to a CString using Format() with formatting codes like %Y, %m, etc. Maybe somebody has written a class, derived from CTime, that could handle this? Jimmy Ehrnström

        N Offline
        N Offline
        Not Active
        wrote on last edited by
        #3

        VarDateFromStr

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups