Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Long Date Function
#1
Code: (Select All)
Function lDate$
    p$ = "th"
    If Val(Mid$(Date$, 4, 2)) <= 9 Then
        day$ = Right$(Mid$(Date$, 4, 2), 1)
    Else
        day$ = Mid$(Date$, 4, 2)
    End If
    If Val(Mid$(Date$, 4, 2)) = 1 Or Val(Mid$(Date$, 4, 2)) = 21 Or Val(Mid$(Date$, 4, 2)) = 31 Then p$ = "st"
    If Val(Mid$(Date$, 4, 2)) = 2 Or Val(Mid$(Date$, 4, 2)) = 22 Then p$ = "nd"
    If Val(Mid$(Date$, 4, 2)) = 3 Or Val(Mid$(Date$, 4, 2)) = 23 Then p$ = "rd"

    Select Case Val(Mid$(Date$, 1, 2))
        Case 1: Month$ = "January"
        Case 2: Month$ = "February"
        Case 3: Month$ = "March"
        Case 4: Month$ = "April"
        Case 5: Month$ = "May"
        Case 6: Month$ = "June"
        Case 7: Month$ = "July"
        Case 8: Month$ = "August"
        Case 9: Month$ = "September"
        Case 10: Month$ = "October"
        Case 11: Month$ = "November"
        Case 12: Month$ = "December"
    End Select
    lDate = day$ + p$ + " " + Month$ + " " + Mid$(Date$, 7, 4)
End Function
This code adds a function that will print a long date (21 February 2022) to the screen the instead of using date$ that would print 21-02-2022
Reply
#2
Nice! I love stuff like this. Here's what I used to d a lot of back in the 1990's, to save memory space...

Code: (Select All)
dstring$ = "stndrdthththththth"
mstring$ = "January  February March    April    May      June     July     August   SeptemberOctober  November December "

DO
    LINE INPUT "mo-day-year: ", xdate$
    PRINT RTRIM$(MID$(mstring$, (VAL(MID$(xdate$, 1, 2)) - 1) * 9 + 1, 9)); " ";
    PRINT LTRIM$(STR$((VAL(MID$(xdate$, 4)))));
    IF MID$(xdate$, 4, 2) > "10" AND MID$(xdate$, 4, 2) < "21" OR VAL(MID$(xdate$, 5, 1)) = 0 THEN
        PRINT "th, ";
    ELSE
        PRINT MID$(dstring$, VAL(MID$(xdate$, 5, 1)) * 2 - 1, 2); ", ";
    END IF
    PRINT MID$(xdate$, 7, 4)
    PRINT
LOOP

I used what I termed as "Data Strings" to store info. Parse the string and display the results. Saving mem lead to a lot of obfuscated coding but at least it got the program working when space was an issue.

Pete
Reply
#3
Even less LOC
Code: (Select All)
Do
    Line Input "mo-day-year: ", xdate$
    Print RTrim$(Mid$("January  February March    April    May      June     July     August   SeptemberOctober  November December ", (Val(Mid$(xdate$, 1, 2)) - 1) * 9 + 1, 9)); " ";
    Print LTrim$(Str$((Val(Mid$(xdate$, 4)))));
    If Mid$(xdate$, 4, 2) > "10" And Mid$(xdate$, 4, 2) < "21" Or Val(Mid$(xdate$, 5, 1)) = 0 Then
        Print "th, ";
    Else
        Print Mid$("stndrdthththththth", Val(Mid$(xdate$, 5, 1)) * 2 - 1, 2); ", ";
    End If
    Print Mid$(xdate$, 7, 4)
    Print
Loop
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Function IsWord%(test$) bplus 5 186 02-26-2026, 02:51 PM
Last Post: mdijkens
  PrintW - print a long string, breaking it at the last space or hyphen before col. 79 TDarcos 21 3,960 04-22-2024, 09:52 PM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)