BB___DATE

=DATE$= toc

Description
> This function returns **today's date** as a string or returns a **numeric value** of the number of days passed since Jan 1, 1901. The numeric value allows using date$ for math operations.

> Additionally, one form of date$ returns a string value of **any date** given.

> See also TIME$

Today's date
//These forms return a STRING with today's date formatted as shown.// //The last form is often used for sorting.//
 * date$ || spaces || Sep 21, 2010 ||
 * date$("mm/dd/yyyy") ||  || 09/21/2010 ||
 * date$("mm/dd/yy") ||  || 09/21/10 ||
 * date$("yyyy/mm/dd") ||  || 2010/09/21 ||

Days passed
//These forms return the NUMBER of days passed from Jan 1, 1901 until today, or until the date given.//
 * date$("days") || spaces || 40075 ||
 * date$("09/11/2001") ||  || 36778 ||

Any date
//This form returns a string representation of any date, given the number of days since 1/1/1901.//
 * date$(40075) || spaces || 09/21/2010 ||

Hints
> The result of date$ can be assigned to a variable. e.g. d$ = date$

> For database use, store dates in numeric format to save space and to make the dates immediately available for math operations. e.g. Searching records to find the newest or oldest date.

> When using date$ with an included date, the date can take any of these formats: > If only the last 2 digits of year are given, the first digits are assumed to be 20. e.g. "4/1/02" = "4/1/2002"
 * 1) date$("4/1/02")
 * 2) date$("1/1/1901")
 * 3) date$("April 1, 2002")
 * 4) date$("Apr 1, 2002")

> You can use date$ to easily check if entered date is valid: >> print date$("09/31/2010")<> 0 '0 means invalid date >> print date$("09/29/2010")<> 0 '1 means valid date > See Useful Functions

Getting today's date
code format="lb" print date$ print date$("mm/dd/yyyy")

' The date$ result can be assigned to a variable. d$ = date$("mm/dd/yyyy") print d$ code

Date$ math
code format="lb" ' A simple use of math with date$, and showing use of ' numeric variables holding the result of date$. input "Please enter your birthday as mm/dd/yyyy: ";bd$ born = date$(bd$)     ' returns numeric format of birthday today = date$("days") ' returns numeric form of today ' Do the math... daysOld = today - born print "Today, you are "; daysOld; " days old!" ' Check if correct result print "That is "; daysOld/365; " years." end code

Check for Leap Year
code format="lb" Function IsLeapYear(year) ' returns 1, if the specified year is a leap year, ' 0 otherwise. year must include the century as in 1980

IsLeapYear = date$("2/29/"; year) <> 0 End Function code

Check for Valid Date
code format="lb" Function IsValidDate(d$) ' returns 1, if the date represented by d$ is valid, 0 if not

IsValidDate = date$(d$) <> 0 End Function code

Day of Week from Days
This takes the day as the number of days since Jan 1st, 1901 code format="lb" 'examples of usage print weekDayFrDay$(date$("days"))     'now print weekDayFrDay$(date$("days")+1)   'tomorrow print weekDayFrDay$(date$("days")-7)   'week ago print date$(40000), weekDayFrDay$(40000)   'some random date

function weekDayFrDay$(d) w = (d + 2) mod 7 weekDayFrDay$ = word$("Sunday Monday Tuesday Wednesday Thursday Friday Saturday", w+1) end function code

Day of Week from Date
This takes the day as a date. code format="lb" 'examples of usage print weekDayfrString$("09/32/2010")   'invalid date print weekDayfrString$("09/29/2010")   'valid date

function weekDayfrString$(d$) d = date$(d$) if d = 0 then weekDayfrString$ = "Invalid date ";d$ else w = (d + 2) mod 7 weekDayfrString$ = word$("Sunday Monday Tuesday Wednesday Thursday Friday Saturday", w+1) end if end function code