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

Resources
Web Sites
More Tutorials
Vendors
Books
Magazines
NewsLetters
NewsGroups
Forums
User Groups
Talk Shows
Blogs

GBIC >> QBasic >> Tutorial >> Date/Time

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

Date/Time Functions Summary
QBasic has relatively few date/time related functions. They can be categorized as follows:

    • Properties
     date$, time$ 
    • Intervals   
     timer, sleep, wait

Date/Time Function Reference
Here's a quick reference of the available date/time functions, in alphabetical order.

  • date$ - sets or returns the date on a computer
        result$ = date$         # returns "08-12-2008"  (today's date)
        date$ = "08-12-2008"    # sets computer time to 08-12-2000
        

  • sleep - suspends program execution
        sleep 10       # 10 second suspension
        

    Note: If seconds is 0 or omitted, program is suspended until any key is pressed or until a trapped event occurs.

  • time$ - sets or returns the time on a computer
        result$ = time$         # returns "16:54:18"    (24-hour format)
        time$ = "16:54:18"      # sets computer time to 08-12-2000
        

  • timer - returns seconds since midnight OR creates event at specific elapsed time
        result = timer       # returns a number, such as 60959.05
    
        timer ON             # enables timer event trapping
        timer OFF            # disables timer event trapping
        timer STOP           # suspends timer event trapping. 
                               event processing occurs once 
                               timer ON is used again.
        On timer(n%) GoSub Line  
                             # n% is seconds before On Timer branches
                             # n% has 24-hour maximum (86,400 seconds)
        

  • wait - suspends program execution until bit pattern received from input port
        wait port%, AND-expression%, XOR-expression
                  # port% is number of input port
                  # AND-expression% is bit pattern to watch for
                  # XOR-expression% optionally turns bits on
                    before AND operation
        

If you have any suggestions for additions to these tutorials, please let me know.