Computer for SEE and NEB

It is a complete SEE and NEB solution for computer science. It includes Computer Fundamentals, Database (SQL), Programming in C QBASIC, CSS, JavaScript, and PHP for beginners.

Post Top Ad

Your Ad Spot

Wednesday, February 16, 2022

DATE and TIME functions in QBASIC

 

DATE and TIME Functions


DATE$ and TIME$ are the date and time functions. These functions are used both as statements and functions. When DATE$ and TIME$ are used as a function, they are used to return current system date and time whereas when they are used as statement they are used to set the system date and time.

 

DATE$ and TIME$ as Function

DATE$ and TIME$ functions returns the current system date and time of computer respectively. The format of date in the system is mm-dd-yyyy and the format of time is hh:mm:ss in 24 hour time format.

Syntax:         

DATE$

TIME$

 

Example

REM Example of DATE and TIME function

CLS

PRINT "The date is="; DATE$

PRINT "The time is="; TIME$

END

Output



 

                 

The date and time are typically more useful when the individual values (month, year, minute) are placed into individual numerical variables. The date and time are in string format, so they must be converted to numerical variables. The following program demonstrates how to do this by using the VAL(), LEFT$(), RIGHT$, and MID$() functions.

 

CLS

PRINT "Date zone"

d$ = DATE$

month = VAL(MID$(LEFT$(d$, 2)))

date = VAL(MID$(d$, 4, 2))

year = VAL(RIGHT$(d$, 4))

PRINT d$

PRINT date

PRINT year

PRINT : PRINT

PRINT "Time zone"

t$ = TIME$

hour = VAL(MID$(LEFT$(t$, 2)))

minute = VAL(MID$(t$, 4, 2))

second = VAL(RIGHT$(t$, 2))

PRINT t$

PRINT minute

PRINT second

END
Output


 
 

DATE$ and TIME$ as Statement:

When DATE$ and TIME$  are used as statements they are used to set the computer’s date and time. The format of date is mm:dd:yyyy and time is hh:mm:ss in 24 hour clock format.

Syntax:

DATE$ = “string expression

TIME$ = “ string expression”

Example:

REM Example of DATE and TIME statement

CLS

DATE$ = "8-11-2012"

TIME$ = "14:20"

PRINT DATE$

PRINT TIME$

END

Output

 


 


No comments:

Post a Comment

Post Top Ad

Your Ad Spot

Pages