Date Format from YYYY-M-DD to YYYY-MM-DD

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Date Format from YYYY-M-DD to YYYY-MM-DD

Post by Subas » Mon Jul 15, 2013 1:08 am

Dear Friends of LiveCode.

Based on my simple codes, I am seeing the following:

1) When the stack open, the message box shows me the following format:

7/15/13

2) Thanks to a user on LiveCode I manage to use his example which turns the above format to the following:

2013-7-15

3) What I am trying to achieve is the following format:

13-7-15

Can friends of LiveCode help in showing me how to change the year from YYYY to YY.

Code: Select all

on preOpenStack

   put "" into field "Field4" 
   put "" into field "Field1"   

answer the Date
put the Date into fDate
convert fDate to dateitems 
put (the item 1 of fDate) & "-" & (the item 2 of fDate) & "-" & (the item 3 of fDate) into field "Field1"

end preOpenStack
Thank You.

Best Regards
Last edited by Subas on Mon Jul 15, 2013 7:22 am, edited 1 time in total.

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

Re: Date Format from YYYY-M-DD to YY-M-DD

Post by dunbarx » Mon Jul 15, 2013 1:22 am

Hi.

So if you get the short date, which is of the form mm/dd/yy:

set the itemDelimiter to "/"
then assemble item 3, item 1 and item 2 with dashes.

You already seem to mostly have this. Am I misunderstanding?

Craig Newman

Subas
Posts: 32
Joined: Mon May 20, 2013 5:15 am

Re: Date Format from YYYY-M-DD to YY-M-DD

Post by Subas » Mon Jul 15, 2013 7:21 am

Dear Craig and Friends

i made a mistake. Actually the format i wanted is suppose to be:

2013-07-15

Based on my codes i am getting the following:

2013-7-15

i need to change the YYYY-M-DD to YYYY-MM-DD.

Please help.

Best Regards
Subas

shaosean
Posts: 906
Joined: Thu Nov 04, 2010 7:53 am

Re: Date Format from YYYY-M-DD to YYYY-MM-DD

Post by shaosean » Mon Jul 15, 2013 8:28 am

Code: Select all

put "2013-7-15" into tMoo
set the itemDelimiter to "-"
put format("%02s", item 2 of tMoo) into item 2 of tMoo
put tMoo

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

Re: Date Format from YYYY-M-DD to YYYY-MM-DD

Post by dunbarx » Mon Jul 15, 2013 2:48 pm

What shaosean said.

But since you are learning liveCode, please examine this much more pedestrian solution. It will teach you just a little bit about managing text:

Code: Select all

on mouseUp
   get the date
   convert it to dateitems
   if the length of item 2 of it = 1 then put "0" before item 2 of it
   answer item 1 to 3 of it
end mouseUp
Craig Newman

Post Reply