Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Difference Between Two Dates

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-29-2007, 02:39 PM
Newbie
 
Join Date: Apr 2007
Posts: 2
Cool Difference Between Two Dates


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.:
Reply With Quote
  #2 (permalink)  
Old 07-29-2007, 03:03 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 993
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Hello dvanwig,

the DateAdd function is a powerful way for every date calculation.

You should code something like this:
Code:
tenDaysBeforeBirthDayInTicks = DateAdd(bithdayInTicks, 00, -10))

specci48
Reply With Quote
  #3 (permalink)  
Old 07-29-2007, 03:45 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

Another solution is to use the cTickPer... constants:
Code:
DaysBetween = Int((Date2-Date1)/cTicksPerDay)
Reply With Quote
  #4 (permalink)  
Old 07-30-2007, 11:47 AM
Newbie
 
Join Date: Apr 2007
Posts: 2
Thumbs up Difference Between Two Dates

Thank you Specci48 and Erel for the sugestions.
Reply With Quote
  #5 (permalink)  
Old 08-01-2007, 04:51 PM
Junior Member
 
Join Date: May 2007
Posts: 31
Default 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.
Reply With Quote
  #6 (permalink)  
Old 08-01-2007, 07:48 PM
specci48's Avatar
Basic4ppc Expert
 
Join Date: Apr 2007
Location: Germany
Posts: 993
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

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
Reply With Quote
  #7 (permalink)  
Old 08-01-2007, 08:00 PM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 13,162
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

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.
Reply With Quote
  #8 (permalink)  
Old 08-02-2007, 05:29 AM
Junior Member
 
Join Date: May 2007
Posts: 31
Talking 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

It works!!!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
help with dates adbftrainer Questions (Windows Mobile) 3 08-31-2008 06:56 PM
Confused sorting on SQLLite dates mikewhite Questions (Windows Mobile) 4 08-18-2008 09:16 PM
What's The Difference? Louis Chit Chat 1 03-08-2008 09:38 AM
How many days between two dates pmu5757 Questions (Windows Mobile) 3 09-21-2007 11:27 AM
How can i compare 2 Dates Fontanus Questions (Windows Mobile) 3 05-04-2007 10:37 PM


All times are GMT. The time now is 03:55 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0