four digit year
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
four digit year
Hi all,
how is it possible to convert a 2 digit year into a 4 digit (16 > 2016)?
I have today date into a field, if I run the app on win I have 27/02/2016 whereas running in android it returns 27/02/16
thanks
franco
how is it possible to convert a 2 digit year into a 4 digit (16 > 2016)?
I have today date into a field, if I run the app on win I have 27/02/2016 whereas running in android it returns 27/02/16
thanks
franco
Re: four digit year
Hi Franco,
You might maybe use the seconds to compare dates
Best regards
Jean-Marc
You might maybe use the seconds to compare dates
Best regards
Jean-Marc
https://alternatic.ch
Re: four digit year
If you look up "convert" you will see various permutations of what you can identify as standardised date/time elements.
If you convert to seconds, you will definitely be able to compare like for like.
Also check "useSystemDate" to see how the user's local settings may be checked for a like for like comparison.
If you convert to seconds, you will definitely be able to compare like for like.
Also check "useSystemDate" to see how the user's local settings may be checked for a like for like comparison.
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: four digit year
Here's a function I use in my iOS app. I think I adapted it from one of Jacqueline's stacks. You should be able to pick it apart to get what you need.
Code: Select all
function formattedDate pDate
if pDate is empty or pDate is not a date then put the short english date into pDate
convert pDate from short english date to dateItems
put item 3 of pDate into theDay
put item 2 of pDate into theMonth
put item 1 of pDate into theYear
put theMonth & "/" & theDay & "/" & theYear into tFormattedDate
return tFormattedDate
end formattedDate
Tom
MacBook Pro OS Mojave 10.14
MacBook Pro OS Mojave 10.14
Re: four digit year
thanks all for replies but, probably I have not explained my need correctly. I do not want to compare dates I only want to have the year of a date extended, complete.
16 = 2016
15 = 2015
and useSystemDate do not work on android
franco
16 = 2016
15 = 2015
and useSystemDate do not work on android
franco
Re: four digit year
in the dictionary I've sow, at the voice dateFormat some "incantations" like %m, %d, %y and this:
%Y Four-digit year: This incantation indicates the year as a four-digit number (including the century)
my question is: is it possible to use these incantations to format a date?
ciao
franco
%Y Four-digit year: This incantation indicates the year as a four-digit number (including the century)
my question is: is it possible to use these incantations to format a date?
ciao
franco
Re: four digit year
The dateformat function is read-only. It reports the user's system date format.
The function quailcreek posted is what many of us use. I'm not sure I'm the author of that exact handler but I use one very similar. Parsing the dateitems is the easiest way to do it. You could also try the "format" function if you are comfortable with that.
The function quailcreek posted is what many of us use. I'm not sure I'm the author of that exact handler but I use one very similar. Parsing the dateitems is the easiest way to do it. You could also try the "format" function if you are comfortable with that.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: four digit year
ok, finally I got the format date that I wanted, dd/mm/yyyy. maybe other shorter and smartest way but, this is what I was able to do:
ciao
franco
Code: Select all
if the environment is "mobile" then --se l'ambiente è mobile elabora la data in formato gg/mm/aa
put the system date into tdate
set the itemDelimiter to "/"
if the number of chars OF item 1 of tdate = 1 then
put 0 BEFORE item 1 of tdate
end if
if the number of chars OF item 2 of tdate = 1 then
put 0 BEFORE item 2 of tdate
end if
put item 2 of tdate into tGiorno
put item 1 of tdate into tMese
put the internet date into tDataInternet --ricava l'anno a 4 cifre
convert tDataInternet from internet date to dateItems
set itemdel to ","
put item 1 of tDataInternet into tAnno
put tGiorno & "/" & tMese & "/" & tAnno into field "fldData"
else
put the system date into field "fldData" --se l'ambiente è win imposta la data del giorno nel campo data
end if
franco
Re: four digit year
I see, you want all the date items expanded, not just the year. Your way works fine, you can feel good about that. Here's another way if you're interested:
Code: Select all
function fDate pDate
if pDate = "" then put the date into pDate
convert pDate to dateitems
set the numberformat to "00"
repeat for each item i in "3,2,1"
put (item i of pDate + 0) & slash after tFDate -- any math operation applies the numberformat
end repeat
delete last char of tFDate -- trailing slash
return tFDate
end fDate
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: four digit year
yes, sorry. I don't well explained.jacque wrote:I see, you want all the date items expanded, not just the year...
"I feeeeel good, I knew that I would, now..."jacque wrote:.. Your way works fine, you can feel good about that...
I only have adapted two different codes found here on the forum, sorry I don't remember who are the authors ( for the first part maybe Klaus )
I've tried your solution so:
Code: Select all
on mouseUp
ask "Data:"
put it into pDate
put fDate( pDate) into tData
answer tData
end mouseUp
function fDate pDate
if pDate = "" then put the date into pDate
convert pDate to dateitems
set the numberformat to "00"
repeat for each item i in "3,2,1"
put (item i of pDate + 0) & slash after tFDate -- any math operation applies the numberformat
end repeat
delete last char of tFDate -- trailing slash
return tFDate
end fDate
if I'm not wrong, convert command not considers the date format g/m/yy a valid date.
so, if I input manually a date using my natural format, the day first, ( pDate is not empty) pDate is not converted in dateitems.
if pDate is empty and then septate with "the date" the function works correctly.
a question about dateitems: ie. today date: 2016,3,1,0,0,0,3 what are items after the date (0,0,0,3)
ciao
franco
Re: four digit year
Hi Franco,
Best
Klaus
the dictionary will not lie to you!francof wrote:a question about dateitems: ie. today date: 2016,3,1,0,0,0,3 what are items after the date (0,0,0,3)

Best
Klaus
-
- Posts: 746
- Joined: Sun Feb 04, 2007 11:01 pm
Re: four digit year
Klaus wrote:Hi Franco,the dictionary will not lie to you!francof wrote:a question about dateitems: ie. today date: 2016,3,1,0,0,0,3 what are items after the date (0,0,0,3)![]()
Best
Klaus
hi Klaus,
whoops

so converting "the time" (7:25pm) also returns the date (01/03/16 7:25pm) which items are 2016,3,1,19,25,0,3 (the last for tuesday)
quailcreek wrote:Who says Germans don't have a sense of humor.

thanks all
franco
Re: four digit year
quailcreek wrote:Who says Germans don't have a sense of humor.



Re: four digit year
In that case you need to tell LC to use the system date format:francof wrote:very good, but it works only with the date format m/g/yy.
if I'm not wrong, convert command not considers the date format g/m/yy a valid date.
Code: Select all
function fDate pDate
set the useSystemDate to true -- add this line
if pDate = "" then put the date into pDate
convert pDate to dateitems
set the numberformat to "00"
repeat for each item i in "3,2,1"
put (item i of pDate + 0) & slash after tFDate -- any math operation applies the numberformat
end repeat
delete last char of tFDate -- trailing slash
return tFDate
end fDate
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com