function to get MM-DD-YY

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

wee wullie
Posts: 78
Joined: Fri Oct 03, 2008 10:13 am

Re: SOLVED function to get MM-DD-YY

Post by wee wullie » Fri Sep 06, 2013 12:44 am

Hi everyone, i managed to solve my problem by dissecting the system date and re-arranging char by char and removing the first 2 digits of the year item, the code i used is thus:

Code: Select all

put text of fld "Date1" into tDate
   put char 4 to 5 of tDate & "/" & char 1 to 2 of tDate & "/" & char 9 to 10 of tDate into fld "Date1"
and it works perfectly, no dateitems, no converting to other formats, just pop it into a var and re-arrange and job done, does seem a little too simple though, but it does work.

Very big thanks to all,

kindest regards

wee

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: function to get MM-DD-YY

Post by dunbarx » Fri Sep 06, 2013 5:53 am

Hi.

Nothing wrong with simple.

But your method relies on a consistent format in your starting date. If you are confident about that, there is no reason not to do it that way. But in general, where the several components of a date might have different numbers of chars, for example, your system would break.

But the exercise itself is just as important. Keep fooling around.

Craig

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: function to get MM-DD-YY

Post by bn » Fri Sep 06, 2013 8:49 am

Hi wee,

sorry I did not read your format correctly.

try this

Code: Select all

on mouseUp
    put text of fld "Date1" into tDate
    set the itemdelimiter to "/" -- this lets you treat a slash as itemDelimiter
    
    put item 2 of tDate into item 1 of tDestFormat -- items are automatically formed with the current itemDelimiter
    put item 1 of tDate into item 2 of tDestFormat
    put char -2 to - 1 of item 3 of tDate into item 3 of tDestFormat -- get only the last two digits
    
    set the itemdelimiter to comma -- be nice and reset the itemDelimiter, would be reset at end of handler anyways though
    
    answer tDestFormat
    
end mouseUp
Kind regards
Bernd

wee wullie
Posts: 78
Joined: Fri Oct 03, 2008 10:13 am

Re: function to get MM-DD-YY

Post by wee wullie » Fri Sep 06, 2013 10:59 am

Nice 1 Bernd, that works perfectly, and thanks to all, i have attached
DateA.rar
(5.12 KiB) Downloaded 330 times
the date picker i use, as i said in an earlier post this date picker was originally on revonline by Marty and was subsequently modified by BVG, i use it in lots of stacks and it works well.

king regards

wee

Post Reply