By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,461 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

How to play around with date?

P: 34
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?
Sep 20 '07 #1
Share this Question
Share on Google+
8 Replies


kadghar
Expert 100+
P: 1,295
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
Sep 20 '07 #2

P: 8
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,"yyyy/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,"yyyy/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
Sep 20 '07 #3

P: 34
Thanks ... for the help.. will try..
Sep 20 '07 #4

P: 34
tRIED.. coolness... thanks again..
Sep 20 '07 #5

P: 34
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...
Sep 20 '07 #6

kadghar
Expert 100+
P: 1,295
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
Sep 20 '07 #7

P: 34
thru trial and error.. found it.. using #..... #...

(DateAdd("m", 1, Date) - #11/15/1977#) .. :)
Sep 20 '07 #8

P: 34
Oh yeah.. ack's works.. too.. thanks
Sep 20 '07 #9

Post your reply

Sign in to post your reply or Sign up for a free account.