Page 1 of 1

DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Posted: Mon Dec 09, 2013 9:20 pm
by LC4iOS
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

   

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Posted: Mon Dec 09, 2013 9:34 pm
by dunbarx
Hi.

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

Craig Newman

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Posted: Mon Dec 09, 2013 10:57 pm
by LC4iOS
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.

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Posted: Tue Dec 10, 2013 12:00 am
by dunbarx
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

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Posted: Tue Dec 10, 2013 12:19 am
by LC4iOS
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?

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Posted: Tue Dec 10, 2013 12:51 am
by dunbarx
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

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Posted: Tue Dec 10, 2013 2:21 am
by LC4iOS
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

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Posted: Tue Dec 10, 2013 2:43 am
by dunbarx
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

Re: DateTimeStamp Sample YYYYMMDDHHMMSS and YYYYMMDD HHMMSS

Posted: Tue Dec 10, 2013 6:25 am
by LC4iOS
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