date and time format (DD/MM/YY)

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 and time format (DD/MM/YY)

Post by Subas » Tue Jun 18, 2013 10:13 am

Dear LiveCode Gurus.

Need so help on date and time. My objective is to:

1st get the user to fill in 2 field of Start time in this format - dd/mm/yy followed by hh:mm. Preferably the user will not have to key in the "/" and ":".
2nd get the user to filed in the Stop time in the same format above fo rhte additional 2 more fields.
3rd take the Stop time - the Start time
4th get the difference and place it into a 5th field.

below are the example codes from codes from a user that I want to modify.

Code: Select all

put field 1 && field 2 into tStartDate
   convert tStartDate to internet date
   put tStartDate into field 6
   convert tStartDate to seconds

put field 3 && field 4 into tEndDate
   convert tEndDate to internet date
   put cr & tEndDate after field 6
   convert tEndDate to seconds
   
   put tEndDate - tStartDate  into tAllSeconds

I have not fully coded the 4th objective as I wanted to ensure that I can achieve objective 1 and 2 first.

Could the LiveCode gurus please help.

Best Regards
Subas

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: date and time format (DD/MM/YY)

Post by bangkok » Tue Jun 18, 2013 1:44 pm

A few ideas :

-create as many fields as piece of data needed : DD + MM + YY + HH + MM
User can tab from one field to the next one
A script does it automatically (with "keydown" message, if the length of me > 2 then select text of field ...)

-dont bother to type the date : use a readymade calendar function (as a modal window for instance), allowing user to click on the date.
Use will have to type only the hour and minute

http://www.troz.net/rev/stacks/Calendar.rev

http://revonline2.runrev.com/stack/646/ ... y-Tim-Bobo

http://www.rotundasoftware.com/livecode ... arPane.php

A very good library to play with dates and times :
http://www.troz.net/rev/stacks/DateTime.rev

As for to convert start and end dates into seconds format, in order to make comparison > or <, that's a good way.

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

Re: date and time format (DD/MM/YY)

Post by dunbarx » Tue Jun 18, 2013 2:05 pm

Hi.

Just to get you started. Make a field. Place this in its script:

Code: Select all

on keydown var
   get me & var
   switch
      case the length of it < 3  and var is an integer
         put var after me
         break
      case the length of it = 3
         put "/" after me
         break
      case the length of it < 6  and var is an integer
         put var after me
         break
      case the length of it = 6
         put "/" after me
         break
      case the length of it > 6  and the length of it < 9 and var is an integer
         put var after me
   end switch
end keydown
Step through the script and you should see how to manipulate data at the character level.

Craig Newman
Last edited by dunbarx on Tue Jun 18, 2013 4:58 pm, edited 1 time in total.

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

Re: date and time format (DD/MM/YY)

Post by Subas » Tue Jun 18, 2013 3:49 pm

Dear dunbarx and Bangkok.

Many Many thanks. both your codes / ideas worked perfectly.

My coding project is getting better by the day and as i just started 2 days ago and for me I am learning how to program much efficiently.

Thanks to all the Live code Gurus and LiveCode itself.

Bravo LivCode and all it's users.

Best Regards
Subas

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: date and time format (DD/MM/YY)

Post by Klaus » Tue Jun 18, 2013 3:52 pm

Hi Subas,

please also check these stacks, great learning resources!
http://www.hyperactivesw.com/revscriptc ... ences.html


Best

Klaus

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

Re: date and time format (DD/MM/YY)

Post by Subas » Wed Jun 19, 2013 12:25 am

Dear klaus.

Thank you for the information. I will look thru the information provided on that URL page.

Best regards
Subas

Post Reply