Getting Started
Introduction
Sample Programs
IDEs
History
Advice
Mini-Tutorial
Tutorials
Code Snippets

Resources
Web Sites
More Tutorials
Forums
Vendors/Tools
Books
Magazines
Newsletters
NewsGroups
User Groups
Talk Shows
Blogs

Controls
Overview
Button
Check3State
Checkbox
ComboBox
Frame
Graphic
Image
ImageX
ImgButton
ImgButtonX
Label
Line
ListBox
ListView
Option
Progress Bar
Scrollbar
StatusBar
TAB
TextBox
Toolbar
TreeView

GBIC >> PowerBASIC >> Tutorials >> Date/Time

PowerBASIC Information Center Tutorials
These tutorials were written to help you get a quick, but thorough, understanding of PowerBASIC - the scope of the language as well as it's specific capabilities.

Introduction       Projects       Language           Messages       Functions           Advanced
  • Overview
  • Examples
  • IDE
  • Compilation
  • Distribution
  • Project Files
  • DDT Windows
  • Controls
  • Menus
  • Dialogs  
  • Help Files
  • Resources  
  • Templates  
  • Project Shell  
  • Syntax
  • Operators
  • Data Types
  • Variables
  • Scope
  • Declarations  
  • Procedures
  • Flow Control
  • Windows
  • Messages
  • Callbacks
  • Mouse
  • Keyboard
  • Dialogs
  • Controls
  • Subclassing
  • Arithmetic
  • Trig  
  • Strings
  • Arrays
  • Date/Time
  • Printing
  • Files
  • Folders
  • Keyboard
  • Mouse
  • Sound
  • System
  • Error Traps
  • Debugging
  • Objects
  • Graphics
  • Databases
  • API
  • DLLs
  • ASM
  • Threads
  • Date/Time Functions Summary
    PowerBASIC has a handful of date/time related functions, categorized as follows.

      • Current Time
       date$, time$
      • Elapsed Time   
       tix, timer
      • Pause Program   
       sleep

    Profiling - Time to Perform Tasks
    A common task is to compare the time taken to run a series of statements. With TIMER, the answer can be retuned with an accuracy of about 0.01 seconds - accurate, but not extremely so. Repeating the code block many times is usually done when TIMER is used.

    When only a relative comparison is acceptable, the use of TIX (CPU cycles) can get very high resolution comparisons, but timing is unknown.

    For high resolution clock time, use the Windows GetTickCount API.

    String Function Listing
    Here's a simple listing of the date/time functions above, with a one-line description of what the function does. Syntax and examples are given in the next section.

    • date$ - get/set system date
    • SLEEP - pause application/thread (milliseconds)
    • TIME$ - get/set system time
    • TIMER - number of seconds since midnight
    • TIX - elapsed CPU cycles.

    Date/Time Functions Reference
    Here are examples for each of the date/time functions. The functions are listed in alphabetical order.

    • DATE$ - get/set system date
          a$ = DATE$       'returns system data
          DATE$ = a$       'set system date
      
          a$ formats:  mm-dd-yy
                       mm/dd/yy
                       mm-dd-yyyy
                       mm/dd/yyyy
          

    • SLEEP - pause application/thread (milliseconds)
          sleep 3000       'pause for 3 seconds
          

    • TIME$ - get/set system time
          a$ = TIME$       'returns system time  :  hh:mm:ss
          TIME$ = a$       'set system time  (hh:mm:ss)
      
          TIME$ = "08:40:00"   ' 8:40am
          TIME$ = "08"         ' 8am
          TIME$ = "15:30"      ' 3:30pm
          TIME$ = "0:01"       ' 1 min after midnight
          

      Time is in 24-hour format.

    • TIMER - number of seconds since midnight
          ElapsedSeconds = TIMER   'seconds since midnight
          

      Return data type is double precision. Resolution is about 1/100 of a second.

    • TIX - elapsed CPU cycles.
          TIX Cycles&&       ' Cycles&& has current value of counter
          TIX END Cycles&&   ' Cycles&& is delta since first call
          

    If you have any suggestions or corrections, please let me know.