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. getting yesterday's date

getting yesterday's date

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 4 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.
  • C Offline
    C Offline
    Camron
    wrote on last edited by
    #1

    Ok i'm using this code to return a date, but the problem is I need the date of the day before this. How could I subtract a day from the date? And what if it's the first of the month, the day before that would be the previous month? Any suggestions? char GTime[80]; time_t now; now = time(NULL); strftime(GTime,sizeof GTime,"%m %d %y\n",localtime(&now)); cout<

    J D realJSOPR 3 Replies Last reply
    0
    • C Camron

      Ok i'm using this code to return a date, but the problem is I need the date of the day before this. How could I subtract a day from the date? And what if it's the first of the month, the day before that would be the previous month? Any suggestions? char GTime[80]; time_t now; now = time(NULL); strftime(GTime,sizeof GTime,"%m %d %y\n",localtime(&now)); cout<

      J Offline
      J Offline
      Jose Lamas Rios
      wrote on last edited by
      #2

      How about substracting (24 * 60 * 60) from the time_t? -- jlr http://jlamas.blogspot.com/[^]

      1 Reply Last reply
      0
      • C Camron

        Ok i'm using this code to return a date, but the problem is I need the date of the day before this. How could I subtract a day from the date? And what if it's the first of the month, the day before that would be the previous month? Any suggestions? char GTime[80]; time_t now; now = time(NULL); strftime(GTime,sizeof GTime,"%m %d %y\n",localtime(&now)); cout<

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        How about:

        time_t now = time(NULL);
        time_t yesterday = now - 86400;


        "Ideas are a dime a dozen. People who put them into action are priceless." - Unknown

        1 Reply Last reply
        0
        • C Camron

          Ok i'm using this code to return a date, but the problem is I need the date of the day before this. How could I subtract a day from the date? And what if it's the first of the month, the day before that would be the previous month? Any suggestions? char GTime[80]; time_t now; now = time(NULL); strftime(GTime,sizeof GTime,"%m %d %y\n",localtime(&now)); cout<

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #4

          COleDateTime odtNow = COleDateTime::GetCurrentTime(); COleDateTimeSpan dtSpan(1,0,0,0); odtNow -= dtSpan; Use MFC - it helps. ------- sig starts "I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

          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