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. ATL / WTL / STL
  4. Programme to add given no of days to the current date to give the resulted date

Programme to add given no of days to the current date to give the resulted date

Scheduled Pinned Locked Moved ATL / WTL / STL
help
8 Posts 2 Posters 1 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
    cmaheshwari16
    wrote on last edited by
    #1

    Hi All, I want a C programme which will take a user input as a date and number of days, and then it will add the given number of days to the input date and will give the resulted date. It should keep in mind all the permutation and combinations like changing month year , leap year, some months have 31 days some have 30 days etc.... for eg.: input date 2010-12-25 days 20 result 2011-01-14 This programme can be made but this will take a lot of time if anybody has similar to that or exact programme then please help.... its just a module. Thanks

    L 1 Reply Last reply
    0
    • C cmaheshwari16

      Hi All, I want a C programme which will take a user input as a date and number of days, and then it will add the given number of days to the input date and will give the resulted date. It should keep in mind all the permutation and combinations like changing month year , leap year, some months have 31 days some have 30 days etc.... for eg.: input date 2010-12-25 days 20 result 2011-01-14 This programme can be made but this will take a lot of time if anybody has similar to that or exact programme then please help.... its just a module. Thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      cmaheshwari16 wrote:

      I want a C programme which will take a user input as a date and number of days,

      A simple search of your C reference or MSDN would have found these routines[^] for you.

      Just say 'NO' to evaluated arguments for diadic functions! Ash

      C 1 Reply Last reply
      0
      • L Lost User

        cmaheshwari16 wrote:

        I want a C programme which will take a user input as a date and number of days,

        A simple search of your C reference or MSDN would have found these routines[^] for you.

        Just say 'NO' to evaluated arguments for diadic functions! Ash

        C Offline
        C Offline
        cmaheshwari16
        wrote on last edited by
        #3

        Sir Thanks for your reply I am working on linux.... and the link you have given... I dont find any function which can add some day to the particular date to give new date. Thanks

        L 1 Reply Last reply
        0
        • C cmaheshwari16

          Sir Thanks for your reply I am working on linux.... and the link you have given... I dont find any function which can add some day to the particular date to give new date. Thanks

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          cmaheshwari16 wrote:

          I dont find any function which can add some day to the particular date to give new date.

          Convert your date to a time_t or a struct tm[^] and some simple mathematics will allow you to calculate your results.

          Just say 'NO' to evaluated arguments for diadic functions! Ash

          C 1 Reply Last reply
          0
          • L Lost User

            cmaheshwari16 wrote:

            I dont find any function which can add some day to the particular date to give new date.

            Convert your date to a time_t or a struct tm[^] and some simple mathematics will allow you to calculate your results.

            Just say 'NO' to evaluated arguments for diadic functions! Ash

            C Offline
            C Offline
            cmaheshwari16
            wrote on last edited by
            #5

            Thanks Richard..... But I was expecting some live example to get the clear understanding... Its now done by using the below way just creating the object of struct tm and then giving the values to the variables of the structure adding the days to the tm_mday variable using the mktime() function, converting it back to a structure..... and then accessing the required values with the structure variable... I still want to understand the use of the time_t.......if u can......

            L 1 Reply Last reply
            0
            • C cmaheshwari16

              Thanks Richard..... But I was expecting some live example to get the clear understanding... Its now done by using the below way just creating the object of struct tm and then giving the values to the variables of the structure adding the days to the tm_mday variable using the mktime() function, converting it back to a structure..... and then accessing the required values with the structure variable... I still want to understand the use of the time_t.......if u can......

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              What you describe above sounds fine. The time_t type is just a value that represents the current time and date as calculated by the OS that you are running on (i.e. Windows, Linux, AIX etc). The struct tm is created by breaking a time_t value into its constituent parts to allow for the type of calculation that you are doing. If you go to the link I gave you for struct tm and look at the menu in the botttom left pane you will see listed all the various time routines, take a look at each of them to see some sample code.

              Just say 'NO' to evaluated arguments for diadic functions! Ash

              C 1 Reply Last reply
              0
              • L Lost User

                What you describe above sounds fine. The time_t type is just a value that represents the current time and date as calculated by the OS that you are running on (i.e. Windows, Linux, AIX etc). The struct tm is created by breaking a time_t value into its constituent parts to allow for the type of calculation that you are doing. If you go to the link I gave you for struct tm and look at the menu in the botttom left pane you will see listed all the various time routines, take a look at each of them to see some sample code.

                Just say 'NO' to evaluated arguments for diadic functions! Ash

                C Offline
                C Offline
                cmaheshwari16
                wrote on last edited by
                #7

                Hi Richard, Now its more clear...... Thanks

                L 1 Reply Last reply
                0
                • C cmaheshwari16

                  Hi Richard, Now its more clear...... Thanks

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  You're welcome.

                  Just say 'NO' to evaluated arguments for diadic functions! Ash

                  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