DATE$ - QB64 Wiki

DATE$

From QB64 Wiki

Jump to: navigation, search

The DATE$ Function returns the present computer date as a string in a month, day and 4 digit year format.


Syntax: today$ = DATE$


  • Returns the present computer date in a mm-dd-yyyy format such as: "12-25-2009"
  • Returns "-" (dash) separators between month, day and year on most machines.
  • NOTE: Older computers may just use the last two digit years!


Example: Displaying the weekday and current date.

PRINT DATE$ month$ = LEFT$(DATE$, 2): M = VAL(month$) day$ = MID$(DATE$, 4, 2): D = VAL(day$) day$ = STR$(D) ' eliminate any leading zeros year$ = RIGHT$(DATE$, 4): Y = VAL(year$) SELECT CASE M CASE 1: Moon$ = "January" CASE 2: Moon$ = "February" CASE 3: Moon$ = "March" CASE 4: Moon$ = "April" CASE 5: Moon$ = "May" CASE 6: Moon$ = "June" CASE 7: Moon$ = "July" CASE 8: Moon$ = "August" CASE 9: Moon$ = "September" CASE 10: Moon$ = "October" CASE 11: Moon$ = "November" CASE 12: Moon$ = "December" END SELECT PRINT "Today is " + WeekDay$(M, D, Y) + ", " + Moon$ + day$ + ", " + year$ + SPACE$(10) FUNCTION WeekDay$ (M, D, Y) IF M < 3 THEN M = M + 12: Y = Y - 1 'add 12 to Jan - Feb month, -1 year C = Y \ 100: Y = Y MOD 100 'split century and year number S1 = (C \ 4) - (2 * C) - 1 'century leap S2 = (5 * Y) \ 4 '4 year leap S3 = 26 * (M + 1) \ 10 'days in months WkDay = (S1 + S2 + S3 + D) MOD 7 'weekday total remainder IF WkDay < 0 THEN WkDay = WkDay + 7 'Adjust negative results to 0 to 6 SELECT CASE WkDay CASE 0: day$ = "Sunday" CASE 1: day$ = "Monday" CASE 2: day$ = "Tuesday" CASE 3: day$ = "Wednesday" CASE 4: day$ = "Thursday" CASE 5: day$ = "Friday" CASE 6: day$ = "Saturday" END SELECT WeekDay$ = day$ END FUNCTION

Code by Ted Weissgerber

06-02-2010 Today is Wednesday, June 2, 2010

NOTE: When using DEFINT A-Z in the main program, place DEFINT A-Z before FUNCTION WeekDay$ line.


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
Views
  • Page
  • Discussion
  • View source
  • History
Personal tools
  • Log in
Toolbox
  • What links here
  • Related changes
  • Special pages
  • Printable version