Main
   Home
   About
   DiscussionBoard
Files
   About
   Submit
   Search
Downloads
   Action
   QB64
Links
   Link to us
QB45.org
[ Back to QB45 | FAQ | Search a message | Reply to this message | Back to messages ]

gablea on 08/20/11 - 17:49:25

Hi all

how do I format a date in QuickBasic 7.1?

I tried to use Format$(Now$,"dd/mm/yyyy") but it errors out

do I need to use another unit?

Todd on 09/07/11 - 14:11:06

Sorry for a late reply. See if this helps. It's some code I wrote to format dates if FORMAT$ doesn't work. I used it in QB 4.5 and it works fine.



FUNCTION FORMAT$ (d$, f$)
out$ = ""
' Search for 'm', 'd', and 'y'
yc% = 0
mc% = 0
dc% = 0
f$ = f$ + "@" ' this is my way of cutting corners...
' Instead of writing a helper function called in CASE ELSE and at the end,
' I'll invoke it again in CASE ELSE by appending a random char, then removing it.
FOR i% = 1 TO LEN(f$)
SELECT CASE MID$(f$, i%, 1)
CASE "d"
dc% = dc% + 1
CASE "m"
mc% = mc% + 1
CASE "y"
yc% = yc% + 1
CASE ELSE
IF (yc% = 2) OR (yc% = 4) THEN
out$ = out$ + RIGHT$(d$, yc%)
ELSEIF mc% = 1 THEN
out$ = out$ + LTRIM$(STR$(VAL(LEFT$(d$, 2))))
ELSEIF mc% = 2 THEN
out$ = out$ + LEFT$(d$, 2)
ELSEIF dc% = 1 THEN
out$ = out$ + LTRIM$(STR$(VAL(MID$(d$, 4, 2))))
ELSEIF dc% = 2 THEN
out$ = out$ + MID$(d$, 4, 2)
END IF
yc% = 0
mc% = 0
dc% = 0
out$ = out$ + MID$(f$, i%, 1)
END SELECT
NEXT
FORMAT$ = LEFT$(out$, LEN(out$) - 1)
END FUNCTION


Reply to this message
Name:
Message:
Please enter this number:
No HTML allowed. You may use BB-code in your posting.
Members
Login
Register
QB45 Members
Member List