How to play around with date?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GROG
    New Member
    • Sep 2007
    • 34

    How to play around with date?

    Hi all... i'm a beginner... i have problems dealing with date.. My Question are:

    1. i want to delete a set of record having todays date rollback till a year ago.. how can i put this into vb codes? ( from today(DD/MM/YYYY) till DD/MM/YYYY -1). Can i extract part by part of the date .. for exmple just want the date (DD)

    2. can i get duration of days after substracting/adding(sum) two dates? How do i code this?
  • kadghar
    Recognized Expert Top Contributor
    • Apr 2007
    • 1302

    #2
    Originally posted by GROG
    Hi all... i'm a beginner... i have problems dealing with date.. My Question are:

    1. i want to delete a set of record having todays date rollback till a year ago.. how can i put this into vb codes? ( from today(DD/MM/YYYY) till DD/MM/YYYY -1). Can i extract part by part of the date .. for exmple just want the date (DD)

    2. can i get duration of days after substracting/adding(sum) two dates? How do i code this?
    1. use the function DateAdd ( interval, number, date)
    e.g
    msgbox(dateadd( "yyyy", 1, date)
    will give you a message box with today plus one year

    2 sure, just substract them

    msgbox (dateadd("m",1, date) -date)
    will give you around 30

    date is today's date
    Last edited by kadghar; Sep 20 '07, 04:04 PM. Reason: add a comment

    Comment

    • Ack Programming
      New Member
      • Sep 2007
      • 8

      #3
      If you keep every thing in a date format you can like:
      format(now,"dd/mm/yyyy") - and use Smaller than (< or >) for comparesins
      then you can do menny things like:
      Declare a Varible Like :

      -Dim My_Date string
      -Dim Year as Integer
      -New_Date as Date

      - My_Date = Format(Now,"yyy y/mm/dd") 'The Reason for this is becayse vb's date is swinged around
      - My_Date = Left(My_Date,4)
      - Year = Int(My-Date)
      - Year = Year - 1
      - My_Date = Format(Now,"yyy y/mm/dd")
      - My_Date = Right(My_Date,6 )
      - My_Date = trim(str(Year)+ My-Date
      - New_Date = My_Date

      Then Simply Use A Comparison Like

      Delete Older Date<New_Date

      Try That

      Comment

      • GROG
        New Member
        • Sep 2007
        • 34

        #4
        Thanks ... for the help.. will try..

        Comment

        • GROG
          New Member
          • Sep 2007
          • 34

          #5
          tRIED.. coolness... thanks again..

          Comment

          • GROG
            New Member
            • Sep 2007
            • 34

            #6
            Kadghar,

            given...
            DateAdd("m", 1, Date) - Date)

            what if i wanna change the Date (which is today) to any given date i.e 15/12/1967?
            how do we code that ? substraction / addition...

            Comment

            • kadghar
              Recognized Expert Top Contributor
              • Apr 2007
              • 1302

              #7
              Originally posted by GROG
              Kadghar,

              given...
              DateAdd("m", 1, Date) - Date)

              what if i wanna change the Date (which is today) to any given date i.e 15/12/1967?
              how do we code that ? substraction / addition...
              use what ack wrote to define a date type variable and operate it:

              dim myDate as date
              mydate = "15/12/1967"
              msgbox date - mydate

              Comment

              • GROG
                New Member
                • Sep 2007
                • 34

                #8
                thru trial and error.. found it.. using #..... #...

                (DateAdd("m", 1, Date) - #11/15/1977#) .. :)

                Comment

                • GROG
                  New Member
                  • Sep 2007
                  • 34

                  #9
                  Oh yeah.. ack's works.. too.. thanks

                  Comment

                  Working...