using system date calculate last 6 days in c language

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • madhu3437
    New Member
    • Apr 2008
    • 13

    using system date calculate last 6 days in c language

    i am in big problem
    Under unix C Language
    i want return date format like MM/DD/YYYY
    this function should return above format .

    using system date calculate last 6 days mean clearly i am explain

    today date is :06/09/2008

    the function return 06/03/2008

    but when we write program automatic return the last 6 days date means 06/03/2008


    please help .............

    bye
    madhu
  • gpraghuram
    Recognized Expert Top Contributor
    • Mar 2007
    • 1275

    #2
    You should use clock tick to do this.
    What code u have written for this?

    Raghu

    Comment

    • madhu3437
      New Member
      • Apr 2008
      • 13

      #3
      using c language (unix)

      return should this format mm/dd/yyyy

      calculate the last 6 days mean
      using system date - 7 days so we get the last 6 days
      there is no input here automatically get the return the function of last 6 days date
      please help ,......
      i want source code for this

      please please


      thanks
      madhu







      Originally posted by gpraghuram
      You should use clock tick to do this.
      What code u have written for this?

      Raghu

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        On your unix/linux/whatever system type in 'man ctime' and read all about it.

        kind regards,

        Jos

        Comment

        • gpraghuram
          Recognized Expert Top Contributor
          • Mar 2007
          • 1275

          #5
          We cant write code for you.
          The logic u are asking is to some extent simple.
          You should use localtime() and time() functions for this

          Raghu

          Comment

          • madhu3437
            New Member
            • Apr 2008
            • 13

            #6
            i am little bit confusion , code please help,


            Regards,
            Madhu



            Originally posted by gpraghuram
            We cant write code for you.
            The logic u are asking is to some extent simple.
            You should use localtime() and time() functions for this

            Raghu

            Comment

            • madhu3437
              New Member
              • Apr 2008
              • 13

              #7
              i tryied below code........... ......

              #include <time.h>
              #include <stdio.h>

              int main()
              {

              time_t current,c6;

              current = time(NULL);
              c6 = current - (6 * 3600 *24);
              printf("\n Current Time : [%s]", ctime(&current) );
              printf("\n 6 Days before : [%s]", ctime(&c6));

              return 0;
              }

              output give the last 6 days date


              but using this code write the function and return the last 6 days date..

              please help.......
              Regards,
              Madhu





              Originally posted by madhu3437
              i am little bit confusion , code please help,


              Regards,
              Madhu

              Comment

              • JosAH
                Recognized Expert MVP
                • Mar 2007
                • 11453

                #8
                Originally posted by madhu3437
                but using this code write the function and return the last 6 days date..

                please help.......
                I'm sorry I don't understand your question. You have working code that produces
                the correct output using the correct logic. What exactly do you want? I'm afraid
                this is a little English language problem.

                kind regards,

                Jos

                Comment

                • madhu3437
                  New Member
                  • Apr 2008
                  • 13

                  #9
                  #include<stdio. h>
                  #include<time.h >
                  char *functionName() ;
                  int main()
                  {
                  printf("\n date - 6 days : [%s]" , functionName()) ;
                  //Here u will get in full string format then u parce it and use the info what ever required.
                  }

                  char *functionName()
                  {
                  current = time(NULL);
                  c6 = current - (29 * 3600 *24);
                  return ctime(&c6);
                  }

                  output is ::::::::::::::
                  date - 6 days : [Wed Jun 4 17:09:40 2008]


                  i write the above code it returns the last 6 days date
                  so output convert into MM/DD/YYYY [06/04/2008]
                  please help ..............h elp

                  Regards,
                  Madhu





                  Originally posted by JosAH
                  I'm sorry I don't understand your question. You have working code that produces
                  the correct output using the correct logic. What exactly do you want? I'm afraid
                  this is a little English language problem.

                  kind regards,

                  Jos

                  Comment

                  • JosAH
                    Recognized Expert MVP
                    • Mar 2007
                    • 11453

                    #10
                    I'm sorry, I still don't understand what you want. I've asked the other moderators
                    to have a peek; maybe one of them can help you out.

                    kind regards,

                    Jos

                    Comment

                    • madhu3437
                      New Member
                      • Apr 2008
                      • 13

                      #11
                      please some one help


                      help........... .....
                      bye
                      madhu


                      Originally posted by JosAH
                      I'm sorry, I still don't understand what you want. I've asked the other moderators
                      to have a peek; maybe one of them can help you out.

                      kind regards,

                      Jos

                      Comment

                      • JosAH
                        Recognized Expert MVP
                        • Mar 2007
                        • 11453

                        #12
                        Originally posted by madhu3437
                        please some one help


                        help........... .....
                        bye
                        madhu
                        Ok, I'll try again; what should the function do? i.e. what are the input parameter(s)
                        supposed to be, what should the function compute and what should it return?
                        Please don't show us that same code again, try to write the requirements down
                        in English.

                        kind regards,

                        Jos

                        Comment

                        • NeoPa
                          Recognized Expert Moderator MVP
                          • Oct 2006
                          • 32633

                          #13
                          I'm guessing that the OP is simply asking how to format the date in mm/dd/yyyy format (may well be wrong of course).

                          I would comment that this does seem very much like a homework question. I would warn against providing code and suggest simply instructing on how this is done.

                          Comment

                          • mac11
                            Contributor
                            • Apr 2007
                            • 256

                            #14
                            Originally posted by NeoPa
                            I'm guessing that the OP is simply asking how to format the date in mm/dd/yyyy format (may well be wrong of course).

                            I would comment that this does seem very much like a homework question. I would warn against providing code and suggest simply instructing on how this is done.
                            If all you (OP) need to do is change how the date is formatted you might want to look into the strftime function - it's sort of like a sprintf made just for time formatting. Look at your manpages or ask google for documentation.

                            Comment

                            • MMcCarthy
                              Recognized Expert MVP
                              • Aug 2006
                              • 14387

                              #15
                              I would guess that there is a problem with the system date formula. (e.g.) if you try to get a date 6 days before 06/09/2008 then the user has a problem because it is returning 31/08/2008 I guess instead of 06/03/2008 which is what the user wants. The system is reading the date in dd/mm/yyyy format instead of mm/dd/yyyy format.

                              Mary

                              Comment

                              Working...