Discussion:
Dates as numbers in BASIC
(too old to reply)
Kevin Wells
2019-06-25 17:09:26 UTC
Permalink
Hi

How can you get the month as a number instead of the 3 letter shorterned
name e.g?

06 instread of Jun

I know I counld do a routine that gets the 3 letter name and convert
that to the number equivelent, but that would work on English language
computers.

Thanks.
--
Kev Wells
http://kevsoft.co.uk/
carpe cervisium
I went into a theatre as sober as could be,
John Williams (News)
2019-06-25 17:45:46 UTC
Permalink
Post by Kevin Wells
I know I counld do a routine that gets the 3 letter name and convert
that to the number equivelent, but that would work on English language
computers.
Yes!

But do be careful about spelling! Have someone else check it for you.

John
--
John Williams, now back in the UK - no attachments to these addresses!
Non-RISC OS posters change user to johnrwilliams or put 'risc' in subject!
Who is John Williams? http://petit.four.free.fr/picindex/author/
Paul Oates
2019-06-25 18:00:57 UTC
Permalink
I seem to recall there being an OS_Word that dealt with the date & time
format.
Post by Kevin Wells
Hi
How can you get the month as a number instead of the 3 letter shorterned
name e.g?
06 instread of Jun
I know I counld do a routine that gets the 3 letter name and convert
that to the number equivelent, but that would work on English language
computers.
Thanks.
--
Paul Oates
***@btinternet.com
n***@sprow.co.uk
2019-06-27 12:47:59 UTC
Permalink
Post by Kevin Wells
How can you get the month as a number instead of the 3 letter shorterned
name e.g?
06 instread of Jun
DIM block 7
?block=1
SYS"OS_Word",14,block
PRINT block?1

If you want it with leading 0 too change the last line to

PRINT RIGHT$("0"+STR$(block?1),2)

Sprow.
Kevin Wells
2019-06-29 11:23:05 UTC
Permalink
Post by n***@sprow.co.uk
Post by Kevin Wells
How can you get the month as a number instead of the 3 letter shorterned
name e.g?
06 instread of Jun
DIM block 7
?block=1
SYS"OS_Word",14,block
PRINT block?1
If you want it with leading 0 too change the last line to
PRINT RIGHT$("0"+STR$(block?1),2)
Sprow.
Thanks that is what is needed. Nice and simple as well.

Thsmkd to all those who gave other answers as well.
--
Kev Wells
http://kevsoft.co.uk/
carpe cervisium
But it's " Saviour of 'is country " when the guns begin to shoot;
j***@mdfs.net
2019-07-03 18:47:34 UTC
Permalink
Post by n***@sprow.co.uk
DIM block 7
?block=1
SYS"OS_Word",14,block
PRINT block?1
Bear in mind that OSWORD 14 returns BCD values, so you will
get &01 to &09 and &10 to &12 (16-18). num%=VALSTR$~bcd%
will convert it.

jgh

Harriet Bazley
2019-06-25 18:25:42 UTC
Permalink
On 25 Jun 2019 as I do recall,
Post by Kevin Wells
Hi
How can you get the month as a number instead of the 3 letter shorterned
name e.g?
06 instread of Jun
Use OS_Word 14 to read the computer's clock as a 5-byte time value,
then pass the resulting area of memory to OS_ConvertDateAndTime.

The format string for a three-letter shortened month name is %M3 and for
the month in numbers is %MN - see manuals.
--
Harriet Bazley == Loyaulte me lie ==

You cannot kill time without injuring eternity.
Andrew Conroy
2019-06-26 21:19:31 UTC
Permalink
Post by Harriet Bazley
On 25 Jun 2019 as I do recall,
Post by Kevin Wells
Hi
How can you get the month as a number instead of the 3 letter
shorterned name e.g?
06 instread of Jun
Use OS_Word 14 to read the computer's clock as a 5-byte time value,
then pass the resulting area of memory to OS_ConvertDateAndTime.
The format string for a three-letter shortened month name is %M3 and for
the month in numbers is %MN - see manuals.
Or OS_ConvertDateAndTime or, better still,
Territory_ConvertTimeToOrdinals to convert any 5 byte time block rather
than just the current time. You'll then have to parse the result to get
just the month.

Andrew
--
+----------------------------------------+---------------------------------+
| Andrew Conroy, Owl-Art Un-Ltd. | email: ***@argonet.co.uk |
| Coming to you on an Acorn RiscPC SA110 | |
+----------------------------------------+---------------------------------+
The impossible I can do at once, miracles take a little longer!!
Andrew Conroy
2019-06-26 22:05:46 UTC
Permalink
Post by Andrew Conroy
Post by Harriet Bazley
On 25 Jun 2019 as I do recall,
Post by Kevin Wells
Hi
How can you get the month as a number instead of the 3 letter
shorterned name e.g?
06 instread of Jun
Use OS_Word 14 to read the computer's clock as a 5-byte time value,
then pass the resulting area of memory to OS_ConvertDateAndTime.
The format string for a three-letter shortened month name is %M3 and
for the month in numbers is %MN - see manuals.
Or OS_ConvertDateAndTime or, better still,
Territory_ConvertTimeToOrdinals to convert any 5 byte time block rather
than just the current time. You'll then have to parse the result to get
just the month.
There's also Territory_TimeStringToOrdinals which might be easier. Feed
in a dummy time string with the desired month in it, and back comes the
month number at offset &14 in the buffer.

Andrew
--
+----------------------------------------+---------------------------------+
| Andrew Conroy, Owl-Art Un-Ltd. | email: ***@argonet.co.uk |
| Coming to you on an Acorn RiscPC SA110 | |
+----------------------------------------+---------------------------------+
The impossible I can do at once, miracles take a little longer!!
Alan Adams
2019-06-27 11:08:28 UTC
Permalink
Post by Andrew Conroy
Post by Andrew Conroy
Post by Harriet Bazley
On 25 Jun 2019 as I do recall,
Post by Kevin Wells
Hi
How can you get the month as a number instead of the 3 letter
shorterned name e.g?
06 instread of Jun
Use OS_Word 14 to read the computer's clock as a 5-byte time value,
then pass the resulting area of memory to OS_ConvertDateAndTime.
The format string for a three-letter shortened month name is %M3 and
for the month in numbers is %MN - see manuals.
Or OS_ConvertDateAndTime or, better still,
Territory_ConvertTimeToOrdinals to convert any 5 byte time block rather
than just the current time. You'll then have to parse the result to get
just the month.
There's also Territory_TimeStringToOrdinals which might be easier. Feed
in a dummy time string with the desired month in it, and back comes the
month number at offset &14 in the buffer.
Andrew
For example:

DIM wlib_block% 256

DEF FNclocktime
=FNclocktime2("%24:%MI:%SE")

DEF FNclocktime2(format$)
LOCAL rsize%,localtime%,result%
IF LEN(format$) > 127 THEN format$=LEFT$(format$,127)
localtime%=wlib_block%
result%=wlib_block%+60
rsize%=128
?localtime%=3
SYS "OS_Word",14,localtime%
SYS "Territory_ConvertDateAndTime",-1,localtime%,result%,rsize%,format$ TO
,rsize%
REM SYS "OS_ConvertDateAndTime",localtime%,result%,rsize%,format$ TO
,rsize%
?rsize%=13
=$result%

For your case:

FNclocktime2("%M3")

will return the current 3-letter month.
--
Alan Adams, from Northamptonshire
***@adamshome.org.uk
http://www.nckc.org.uk/
Alan Adams
2019-06-27 12:32:46 UTC
Permalink
Post by Alan Adams
Post by Andrew Conroy
Post by Andrew Conroy
Post by Harriet Bazley
On 25 Jun 2019 as I do recall,
Post by Kevin Wells
Hi
How can you get the month as a number instead of the 3 letter
shorterned name e.g?
06 instread of Jun
Use OS_Word 14 to read the computer's clock as a 5-byte time value,
then pass the resulting area of memory to OS_ConvertDateAndTime.
The format string for a three-letter shortened month name is %M3 and
for the month in numbers is %MN - see manuals.
Or OS_ConvertDateAndTime or, better still,
Territory_ConvertTimeToOrdinals to convert any 5 byte time block rather
than just the current time. You'll then have to parse the result to get
just the month.
There's also Territory_TimeStringToOrdinals which might be easier. Feed
in a dummy time string with the desired month in it, and back comes the
month number at offset &14 in the buffer.
Andrew
DIM wlib_block% 256
DEF FNclocktime
=FNclocktime2("%24:%MI:%SE")
DEF FNclocktime2(format$)
LOCAL rsize%,localtime%,result%
IF LEN(format$) > 127 THEN format$=LEFT$(format$,127)
localtime%=wlib_block%
result%=wlib_block%+60
rsize%=128
?localtime%=3
SYS "OS_Word",14,localtime%
SYS "Territory_ConvertDateAndTime",-1,localtime%,result%,rsize%,format$ TO
,rsize%
REM SYS "OS_ConvertDateAndTime",localtime%,result%,rsize%,format$ TO
,rsize%
?rsize%=13
=$result%
FNclocktime2("%M3")
will return the current 3-letter month.
while FNclocktime2("%MN") will return the month number, with 01
representing January.
--
Alan Adams, from Northamptonshire
***@adamshome.org.uk
http://www.nckc.org.uk/
Loading...