[AccessD] Pop-quiz: DateAdd() and negative time values

jeffrey.demulling at usbank.com jeffrey.demulling at usbank.com
Wed Nov 19 12:11:28 CST 2003


I thought it would be either a or d.  But when I ran it I got 12/29/1899
11:00 PM.

I used the following:

Function test()
MsgBox Format(DateAdd("h", -3, #2:00:00 AM#), "mm\/dd\/yyyy hh\:nn AM/PM")
End Function


                                                                                                                                 
                    "Gustav Brock"                                                                                               
                    <gustav at cactus.dk>               To:     "Access Developers discussion and problem solving"                  
                    Sent by:                          <accessd at databaseadvisors.com>                                             
                    accessd-bounces at databasead       cc:                                                                         
                    visors.com                       Subject:     [AccessD] Pop-quiz: DateAdd() and negative time values         
                                                                                                                                 
                                                                                                                                 
                    11/19/2003 11:40 AM                                                                                          
                    Please respond to "Access                                                                                    
                    Developers discussion and                                                                                    
                    problem solving"                                                                                             
                                                                                                                                 
                                                                                                                                 




Boring day.
So here's a quick quiz to wake you up.

The time value of #02:00 AM# equals

   12/30/1899 02:00 AM

What does - off your head - this expression return:

? Format(DateAdd("h", -3, #02:00 AM#),"mm\/dd\/yyyy hh\:nn AM/PM")

a) 12/30/1898 11:00 PM
b) 12/30/1899 01:00 AM
c) 12/30/1899 05:00 AM
d) 12/30/1899 05:00 PM
e) 12/30/1899 11:00 PM

The tricky part is DateAdd(). Format(), it is only for ensuring a
consistent format of the return value.

Morale: Be careful with negative time values.

/gustav

_______________________________________________
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com








More information about the AccessD mailing list