DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

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
LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Post by LC4iOS » Mon Dec 09, 2013 9:20 pm

Just sharing...

Code: Select all

on mouseUp
   
   answer getDateTimeStamp()

   put getDateTimeStamp() into lDT
   put " " after char 8 of lDT
   
   Answer lDT 

end mouseUp

      
Function getDateTimeStamp
  
   put empty into lSpecs
   
   if lSpecs is empty then
      put the seconds into tNow
   else
      put lSpecs into tNow
   end if
   
   convert tNow to dateItems
   
   put item 1 of tNow into tStamp
   
   repeat with x = 2 to 6
      put char -2 to -1 of ("00" & item x of tNow) after tStamp
   end repeat
   
       
   return tStamp
   
end getDateTimeStamp

   
Last edited by LC4iOS on Mon Dec 09, 2013 10:57 pm, edited 1 time in total.
Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

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

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Post by dunbarx » Mon Dec 09, 2013 9:34 pm

Hi.

Did you have a question about this, or are you just sharing?

Craig Newman

LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Post by LC4iOS » Mon Dec 09, 2013 10:57 pm

Happy to share.

Didn't find a previous post.

But since I'm here, I wonder if there is a simpler example that the repeat used.
I'd prefer something thats really easy (easier) to read

Love LiveCodes string handling

I was looking for something closer to
Answer Format(Internet Date, "yyyymmdd hhmmss")

I was using it to display messages in a text field
to make sure the messages were actually getting displayed/updated and were current using the DateTimeStamp (DTS).
Then I wanted to use MyLocalDateTimeStamp to update a SQLite record.
And test it against a SQLite DateTimeStamp if there is one.
etc.
Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

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

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Post by dunbarx » Tue Dec 10, 2013 12:00 am

Hi.

Everyone has their own style. I do notice that you have several lines of code that are superfluous, but often those are remnants of tests, and do no harm. Would this be OK:

Code: Select all

Function getDateTimeStamp
   convert the seconds to dateItems
replace comma with "" in it
   return it
end getDateTimeStamp
Craig

LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Post by LC4iOS » Tue Dec 10, 2013 12:19 am

Yes, very cool.

Love the "IT" special local variable.
Makes me wonder what else I've missed but looking forward to leaning about.

Looks like the milli seconds are included in the dateItems

I thinks thats why we were using the repeat to exclude the milli seconds

Hence my query regarding format of YYYYMMDD HHMMSS

I'll see if I can find a way to limit the format to exclude milliseconds.
Maybe the convert?
Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

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

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Post by dunbarx » Tue Dec 10, 2013 12:51 am

Hi.

Not sure what you mean by "exclude the milliseconds". Converting to dateitems gives:

Year --2013
Month -- 12
Day --9
Hours --18
Minutes --43
Seconds --53
Day of week -- 2 (monday)

You can certainly append the milliseconds to that if you want.

The "it" local variable pops up all over the place. It was born with Hypercard in 1987, and almost was the ONLY variable. Be careful with it, as it changes with many operations. Always put it into another variable right away unless you are sure it will not wander.

Craig

LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Post by LC4iOS » Tue Dec 10, 2013 2:21 am

Excellent! Thanks for that extended repely.
Very happy with the support as I'm refreshing / learning.

Only use the "IT" special local variable if I'm the one setting the value just before I use "IT"

Looks like the milliseconds is actually the Day of week.
Logical deduction incorrect.


Now how to exclude Day of week.

Fun Fun

something like
lDTS = char(1 thru 14) of lDTS
Put char (1 to -2) of lDTS into lDTS
Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

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

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Post by dunbarx » Tue Dec 10, 2013 2:43 am

Hi.

Fun is right.

But a more robust parsing of the dateItems would be independent of whether either the month or day was one or two digits. Go back to the line before we lost all those commas. The format is now set up as a string of items, since commas are the default itemDelimiter. Your move...

Craig

LC4iOS
Posts: 88
Joined: Tue Dec 03, 2013 8:15 pm

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Post by LC4iOS » Tue Dec 10, 2013 6:25 am

LOL yes of course today being the 10th is the first day of the month that is NOT a single digit otherwise I would have caught the anomaly.
And the month being a double date.
No wait the time I started this morn was 6 am.
????
Just checked the seconds come back as 04, 05 etc.
So all are double digits.

Looks like dateItems is smart enough to return double digits for each item.
Thanks RunRev.
Well except for the DayOfWeek which will always be 1 to 7 a single digit.

Code: Select all

on mouseUp
   
    put getDateTimeStamp2() into lDT
   
   put char 1 to -2 of ldt into lDT 
   
   Put ":" after char 12  of lDT
   Put ":" after char 10  of lDT
   
   put " " after char 8 of lDT

   Put "-" after char 6 of lDT
   Put "-" after char 4 of lDT
   

  Answer "DateTime Stamp: " & lDT

end mouseUp


Function getDateTimeStamp2
   
   convert the seconds to dateItems
   replace comma with "" in it
   return it

end getDateTimeStamp2


Thanks to RunRev.
Thanks to LiveCode forum members.

LiveCode v5.5.5 - iOS Android Mac Windows - 6.5 Community
27" 2012 iMac i5, MacBook Pro, MacBook Air, iPhone 5, iPhone 4
xCode 5.0.2 - iOS7 - OS X Mavericks
Paid Apple iOS Developer Program Member

Post Reply