Page 1 of 1
Getting the numeric month from the month name
Posted: Wed Jan 06, 2021 3:09 am
by MichaelBluejay
Using this code, I can get the numeric month from the month name with 3 lines of code:
Code: Select all
put "Jan 1,Feb 2,Mar 3,Apr 4,May 5,Jun 6,Jul 7,Aug 8,Sep 9,Oct 10,Nov 11,Dec 12" into months
split months by comma and space
put months["Jan"]
But I have a hunch it's possible with only two lines of code. Is it?
Re: Getting the numeric month from the month name
Posted: Wed Jan 06, 2021 3:29 am
by rkriesel
Hi, Michael. How about one line?
get lineOffset(tMonth, the abbr monthNames)
-- Dick
Re: Getting the numeric month from the month name
Posted: Wed Jan 06, 2021 4:55 am
by dunbarx
Hah. I can do it in no lines.
It's "1".
Craig
Re: Getting the numeric month from the month name
Posted: Wed Jan 06, 2021 6:50 am
by MichaelBluejay
Thanks, rkriesel, that does the trick.
I was trying to roll my own to convert dates like "Jul 12, 2020" to "7/12/20" because according to the dictionary, "Jul 12, 2020" is not one of the formats that LC can convert to or from, but trying it just now, in fact it can.
Code: Select all
convert "Jul 12, 2020" to short date
put it
--returns 7/12/20
Re: Getting the numeric month from the month name
Posted: Wed Jan 06, 2021 4:51 pm
by dunbarx
Hi.
There are lots of ways to present a date, and we have all had to swap parts around either to fit into one of the acceptable LC formats, or to take a format and fit into a custom one. The "dateItems" is usually your friend.
Craig
Re: Getting the numeric month from the month name
Posted: Wed Jan 06, 2021 5:06 pm
by Klaus
MichaelBluejay wrote: ↑Wed Jan 06, 2021 6:50 am
I was trying to roll my own to convert dates like "Jul 12, 2020" to "7/12/20" because according to the dictionary, "Jul 12, 2020" is not one of the formats that LC can convert to or from, but trying it just now...
-> Jul 12, 2020
IS in fact a date LC can deal with, it is named
-> the abbr date
(abbr = abbreviated for abbreviated

)
Sometimes it is a good idea to tell LC what you want:
Code: Select all
convert "Jul 12, 2020" from abbr date to short date
We also have:
the long date
the internet date
the abbr monthnames
the abbr weekdaynames
And if you are not an english native speaker everything as above but with SYSTEM, gives me everything in german:
the long system date
the abbr system monthnames
the abbr system weekdaynames
Re: Getting the numeric month from the month name
Posted: Fri Jan 08, 2021 8:53 am
by MichaelBluejay
Like I said, the format I want is not listed in the dictionary as one of the formats that LC can deal with.
The format I want ("Jan 8, 2021") is *not* "the abbr date". The "abbr date" returns a date like "Fri, Jan 8, 2021" (adding the "Fri" for the day of the week, which I don't want).
Re: Getting the numeric month from the month name
Posted: Fri Jan 08, 2021 10:55 am
by Klaus
Sorry, my fault!