Walkthrough: Managing Date/Time Data Type

There are 5 CALLBasic commands that require a date/time SQL data type variable:

 

The script below shows examples of using these CALLBasic commands.

CALLBasic Script - GetDate-AddDate-MakeDate.bas Copy to Clipboard
Program
'****************************************************************************************************************
'     Script:  GetDate-AddDate-MakeDate.bas
'     Function:  Manipulate Date Time variable
'****************************************************************************************************************

' Example 1
     ' Make 2 Date/Time data type fields
     ' dteStartDate will be set to current date and time
     ' dteEndDate will be 1 day and 2 hours later than the dteStartDate

     dteStartDate = $today

     dteEndDate = dteStartDate
     intDayInc = 1
     intHourInc = 2
     intMinInc = 0
     intSecInc = 0
     AddDate dteEndDate intDayInc intHourInc intMinInc intSecInc

     Print "Start Date is "
     PrintNL dteStartDate
     Print "End Date is "
     PrintNL dteEndDate

     'If today is 09/30/07 10:30:00 then
     'dteStartDate = 09/30/07 10:30:00
     'dteEndDate = 10/1/07 12:30:00


' Example 2
     ' Get date from a date/time data type system variable, local variable or database field
     ' (e.g. OutcallSchedule date/time field UserDateTime, system variable $oduserdatetime)
     ' Make new date by replacing time component with string system variable
     ' (e.g. OutcallSchedule string field MailBox, system variable $odmailbox)

     ' Get components of $oduserdatetime field or replace with local date variable from Example 1 (dteEndDate)
     dteApptDate = $oduserdatetime

     ' If you do not want to use $oduserdatetime field or replace with local date variable from Example 1.  Uncomment statement below.
     'dteApptDate = dteEndDate

     GetDate dteApptDate intApptMM intApptDay intApptYear intHour intMin intSec

     ' Get time from Mailbox field. Check # of digits to if variable length string provided.
     ' If 3 digits then use digit 1 for hour, digits 2,3 for min else digits 1,2 for hour and digits 3,4 for min
     ApptTime = $odmailbox

    ' If you do not want to use $odmailbox, you can replace with a literal as shown below
     'ApptTime = "945"

     StringLength len ApptTime
     If len = 3 Then
        MemMove strHour ApptTime 0 1
        MemMove strMin ApptTime 1 2
     Else
        MemMove strHour ApptTime 0 2
        MemMove strMin ApptTime 2 2
     EndIf

     ' Convert from string to integer to use with the MakeDate command
     GetInteger intApptHour strHour 0
     GetInteger intApptMin strMin 0
     intApptSec = 0

     ' Make date
     MakeDate dteApptDateTime intApptMM intApptDay intApptYear intApptHour intApptMin intApptSec

     'If $oduserdatetime is 09/30/07 10:30:40 and $odmailbox is "945" then
     'dteApptDateTime = 09/30/07 9:45:00

     ' Use the SayDate command to say the date component
     SayDate dteApptDateTime

     ' Use the SayTime command to say the time component
     SayTime dteApptDateTime

EndProgram