:sign0085: Hi, Can someone help describe how I can calculate the number of days between two dates? Right now I can compare two dates but I don't know how to calculate the number of days between two dates. I'm trying to create a program that will remind me of birthdays and anniversaries 10 days before the event. Thanks for your help.:
Hello dvanwig, the DateAdd function is a powerful way for every date calculation. You should code something like this: Code: tenDaysBeforeBirthDayInTicks = DateAdd(bithdayInTicks, 0, 0, -10)) specci48
Another solution is to use the cTickPer... constants: Code: DaysBetween = Int((Date2-Date1)/cTicksPerDay)
Dates and Days I am attempting to use Erel example in my code. Previously , I was using DateDayofYear- which means that my program would only run on aper year basis. (Lol) So now I have questions about using the Int((DATE-DATE)/cTicksPerDay) Case1- I understand if the date is the first date is x and the second is x then it returns -1 for days in between... that is cool Case2- for x and x+1 it returns 0 days in between ... got it. Case 3- for x and x+2 returns 1 day in between Now what happens if the date captured is at 11:59pm one day and 12:00am the next ... will it return 0 or -1? I am just trying to see if there are any quirks, I do know how to parse the ticks data.
Hi XerVision, there must be something wrong with your implementation of Erel's formula. Can it be that you are doing a subtract of -1 somewhere else in your code? Because in Case1 (Date1 = Date2) Erel's function returns 0 Case2 (Date1 + 1 = Date2) Erel's function returns 1 Case3 (Date1 + 2 = Date2) Erel's function returns 2 And the answer of your last question: If you try Code: D1 = DateParse ("08/01/2007") D1 = D1 + 23 * cTickPerHour D1 = D1 + 59 * cTicksPerMinute D1 = D1 + 59 * cTicksPerSecond D2 = D1 + cTicksPerSecond Label1.Text= Int((D2 - D1)/cTicksPerDay) Label1.Text is 0. specci48
Here is another small tip, if you like to assign d1 the following date and time: 08/01/2007 14:30. Code: d1 = DateParse("08/01/2007") + (TimeParse("14:30") mod cTicksPerDay) msgbox(date(d1),time(d1)) 'just to see the result.
Thanks, Guys CALVLUE and USERSTARTDATECAL_g are in Ticks OffSet=1 'Get the True day index regardless of time date1= date(CALVLUE) date2=date(USERSTARTDATECAL_g) newdate1=DateParse(date1) + (TimeParse("00:00") mod cTicksPerDay) newdate2=DateParse(date2) + (TimeParse("00:00") mod cTicksPerDay) if newdate1 >= newdate2 then TheIndex = Int((newdate1-newdate2)/cTicksPerDay)+OffSet else Msgbox ("Please Enter A Date On or After Your Start Date of " &Date(USERSTARTDATECAL_g), Pname$, cMsgBoxOK) TheIndex=-1 end if Return TheIndex :sign0060: It works!!!