New topic: 

Comparing Dates

<http://forums.realsoftware.com/viewtopic.php?t=46159>

         Page 1 of 1
   [ 6 posts ]                 Previous topic | Next topic          Author  
Message        JohnV          Post subject: Comparing DatesPosted: Thu Dec 06, 
2012 2:52 pm                         
Joined: Sun Jan 28, 2007 2:38 pm
Posts: 144                I am writing this with a system clock set to December 
6, 2012

I am trying to compare two dates:

The dates are:

Dim MyDate as New Date 
Dim DatabaseDate as New Date

I then pull the value  "2012-12-06" from the database and call


DatabaseDate.sqldate="2012-12-06"

Then I compare  

If MyDate = DatabaseDate then
//do something stupid
end if

My problem is that "If MyDate = DatabaseDate" appears to be comparing seconds.

IF MyDate.sqldate = DatabaseDate.sqldate... Works just fine as we are comparing 
strings.

BUT

IF MyDate.sqldate > DatabaseDate.sqldate..  Compiler No Like.


HTH Do i compare 2 dates without writing a function to completely tearing apart 
the dates ?   
                             Top                JohnV          Post subject: 
Re: Comparing DatesPosted: Thu Dec 06, 2012 3:08 pm                         
Joined: Sun Jan 28, 2007 2:38 pm
Posts: 144                Got an ugly hack work round.  Not too painful

Append:

Dim MyDate as New Date 
Dim DatabaseDate as New Date

with

  MyDate.hour=0
  MyDate.Minute=0
  MyDate.Second=0

  DatabaseDate.hour=0
  DatabaseDate.Minute=0
  DatabaseDate.Second=0


About 6 too many lines of code  just to figure out if my dogs birthday was 
yesterday or today:  If you ask me.   
                             Top                ktekinay          Post subject: 
Re: Comparing DatesPosted: Thu Dec 06, 2012 3:53 pm                             
    
Joined: Mon Feb 05, 2007 5:21 pm
Posts: 290
Location: New York, NY                I have a Date module that lets you easily 
do this and much, much more. I should put that up on my web site, but in the 
meantime, let me know if you'd like it. With my module installed, you'd do:
dim MyDate as Date = TodayAtMidnight_MTC
dim DatabaseDate as Date = TodayAtMidnight_MTC
DatebaseDate.SQLDate = "2012-12-06"

// Now compare seconds
      
_________________
Kem Tekinay
MacTechnologies Consulting
http://www.mactechnologies.com/

Need to develop, test, and refine regular expressions? Try RegExRX.
  
                             Top                charonn0          Post subject: 
Re: Comparing DatesPosted: Thu Dec 06, 2012 4:15 pm                             
    
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1028
Location: San Francisco, CA, USA                JohnV wrote:About 6 too many 
lines of code  just to figure out if my dogs birthday was yesterday or today:  
If you ask me.
We can cut that down using the different constructors, e.g.:

Dim date1 As New Date
Dim date2 As New Date(2012, 12, 6, date1.Hour, date1.minute, date1.second)
If date1.TotalSeconds = date2.TotalSeconds Then
  ...
      
_________________
Boredom Software      

    Last edited by charonn0 on Thu Dec 06, 2012 4:18 pm, edited 1 time in 
total.   
                             Top                timhare          Post subject: 
Re: Comparing DatesPosted: Thu Dec 06, 2012 4:16 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11865
Location: Portland, OR  USA                Quote:IF MyDate.sqldate > 
DatabaseDate.sqldate.. Compiler No Like.
That is perfectly legit code.  The compiler should not complain.  Maybe there 
was some other issue?   
                             Top                Akiland          Post subject: 
Re: Comparing DatesPosted: Fri Dec 07, 2012 6:13 am                             
    
Joined: Tue Jan 04, 2011 3:02 am
Posts: 1053
Location: Jönköping, Sweden                Can't Operator_Compare be used for 
this?
I might be way off, but hey it's friday 

Pseudo code..
if date1.Operator_Compare(date2) > 0 then
  Yada, yada, yada
else
  Other Yada, yada, yada
end if
      
_________________
 http://www.linkedin.com/in/albinkiland
Dev. iMac 27" + 2x22" LG (2.8GHz Intel Core i7, 12GB RAM, 120GB SSD) OS X 10.8
REAL.Studio Web Edition 2011r3  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 6 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to