Date Formatting
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Date Formatting
Is there any function to convert a month in text format to a month number? I have a date stored in the format - "DD MMMMMMMM YYYY" e.g. "22 June 2020" and need to convert to a system date. The days and years are fine, however not sure if there is a function to convert the month.
Re: Date Formatting
Hi.
The full name of the month will to throw LiveCode for a loop the way you have it formatted. Any format is fine, but we need to make it into one that LC understands. Check out "dateItems" in the dictionary, as well as "date".
In a button script:
There are a million ways to do this. You need write this function only once, and use it wherever. If you want to save space, you can preset a custom property with the associations of name and number.
The important thing is that when you asked "is there a way...", well, of course there is. Many. The above is long because we have to substitute the long month names explicitly. You might have had a different (peculiar) format that lent itself to more compact gadgetry.
Craig
The full name of the month will to throw LiveCode for a loop the way you have it formatted. Any format is fine, but we need to make it into one that LC understands. Check out "dateItems" in the dictionary, as well as "date".
In a button script:
Code: Select all
on mouseUp
get "22 January 2020"
put getMonth(word 2 of it) & "/" & word 1 of it & "/" & word 3 of it into normalFormat
convert normalFormat to long date --just because
answer normalFormat
end mouseUp
function getMonth tMonth
switch tMonth
case "January"
return "1"
break
case "February"
return "2"
break
case "You get the picture"
--...
end switch
end getMonth
The important thing is that when you asked "is there a way...", well, of course there is. Many. The above is long because we have to substitute the long month names explicitly. You might have had a different (peculiar) format that lent itself to more compact gadgetry.
Craig
Last edited by dunbarx on Thu Jun 25, 2020 1:38 pm, edited 1 time in total.
Re: Date Formatting
Thx Craig, this is exactly what I thought I would need to do. Was just hoping there was a function that I could not find that would do the job 
Re: Date Formatting
Hi,
you may want to search the dictionary for "month". You'll find "function monthNames".
Have fun!
you may want to search the dictionary for "month". You'll find "function monthNames".
Code: Select all
put line 2 of the monthNames
--> "February"
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!
Re: Date Formatting
Well, can you think of a way to write a universal function that would parse all possible formats, however scrambled they are in presenting the various parts of a date or time? And reformat more "standardly"? Check out the various "offset" functions in the dictionary. These can be used to extract strings from a body of text.Was just hoping there was a function that I could not find that would do the job
But how to distinguish a "3", that might indicate a month, from a "5" that might indicate a day? And those two values placed anywhere in a string. A "universal" function may not be possible. Probably why LC does not have one.

Craig
Re: Date Formatting
Or:AxWald wrote: ↑Thu Jun 25, 2020 8:47 amyou may want to search the dictionary for "month". You'll find "function monthNames".Code: Select all
put line 2 of the monthNames --> "February"
Code: Select all
put lineOffset(tMonth, the monthNames) into tMonth
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- Livecode Opensource Backer
- Posts: 10081
- Joined: Fri Feb 19, 2010 10:17 am
Re: Date Formatting
Garden spade time:
- -
- -
Code: Select all
on mouseUp
ask "What month is it? "
if it is not empty then
put it into MESETS
put 1 into LYNE
repeat until line LYNE of fld "MONAT" is empty
if line LYNE of fld MONAT contains MESETS then
put MESETS && "is month number" && LYNE into fld "fM"
end if
add 1 to LYNE
end repeat
end if
end mouseUp
- Attachments
-
- Month Numberer.livecode.zip
- Here's the stack.
- (1.22 KiB) Downloaded 231 times
Re: Date Formatting
Perfect, thx.jacque wrote: ↑Thu Jun 25, 2020 5:22 pmOr:AxWald wrote: ↑Thu Jun 25, 2020 8:47 amyou may want to search the dictionary for "month". You'll find "function monthNames".Code: Select all
put line 2 of the monthNames --> "February"
Code: Select all
put lineOffset(tMonth, the monthNames) into tMonth