Format Current DateTime to 2011 02 01 03:04 ?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Format Current DateTime to 2011 02 01 03:04 ?
Hi all,
I've had a good look around
Can't seem to get the
Format Current DateTime
2011 02 01 03:04
Any help would be greatly appreciated.
I've had a good look around
Can't seem to get the
Format Current DateTime
2011 02 01 03:04
Any help would be greatly appreciated.
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Re: Format Current DateTime to 2011 02 01 03:04 ?
put the seconds into tNow -- 1304807735
convert tNow to dateItems
put item 1 of tNow into tStamp --2011,5,8,8,35,35,1
repeat with x = 2 to 6
put char -2 to -1 of ("00" & item x of tNow) after tStamp -- 20110508083535
end repeat
put char 1 to 4 of tStamp into strMyYear
put char 5 to 6 of tStamp into strMyMonth
put char 7 to 8 of tStamp into strMyDay
put char 9 to 10 of tStamp into strMyHour
put char 11 to 12 of tStamp into strMyMinute
Answer strMyYear && strMyMonth && strMyDay && strMyHour & ":" & strMyMinute --2011 05 08 08:35
that took 12 steps
Anyone have an easier way?
Like format(DateTime, "yyyy mm dd hh:mm")
convert tNow to dateItems
put item 1 of tNow into tStamp --2011,5,8,8,35,35,1
repeat with x = 2 to 6
put char -2 to -1 of ("00" & item x of tNow) after tStamp -- 20110508083535
end repeat
put char 1 to 4 of tStamp into strMyYear
put char 5 to 6 of tStamp into strMyMonth
put char 7 to 8 of tStamp into strMyDay
put char 9 to 10 of tStamp into strMyHour
put char 11 to 12 of tStamp into strMyMinute
Answer strMyYear && strMyMonth && strMyDay && strMyHour & ":" & strMyMinute --2011 05 08 08:35
that took 12 steps
Anyone have an easier way?
Like format(DateTime, "yyyy mm dd hh:mm")
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Re: Format Current DateTime to 2011 02 01 03:04 ?
Barry...
You could put it into a function if you need to use your format a number of times...
be well
Dixie
You could put it into a function if you need to use your format a number of times...
Code: Select all
on mouseUp
put formatDate(the seconds)
end mouseUp
function formatDate theSeconds
convert theSeconds to dateItems
put item 1 to 5 of theSeconds into theSeconds
repeat with count = 2 to 5
if the number of chars of item count of theSeconds < 2 then
put 0 & item count of theSeconds into item count of theSeconds
end if
end repeat
put item 4 of theSeconds & ":" & item 5 of theSeconds into item 4 of theSeconds
delete item 5 of theSeconds
replace comma with space in theSeconds
return theSeconds
end formatDate
Dixie
-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Re: Format Current DateTime to 2011 02 01 03:04 ?
Dixie rescuses again!
Thanks for all that work.
Champion!
I had considered making it a routine
but was hoping the format or formatDate statement was already built into LiveCode.
Thanks for all that work.
Champion!
I had considered making it a routine
but was hoping the format or formatDate statement was already built into LiveCode.
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Re: Format Current DateTime to 2011 02 01 03:04 ?
How about:
4 steps.
Colin?
Code: Select all
on mouseUp
convert the seconds to dateItems
answer item 1 of it && char -2 of ("0" & item 2 of it) & char -1 of ("0" & item 2 of it) &&\
char -2 of ("0" & item 3 of it) & char -1 of ("0" & item 3 of it) &&\
char -2 of ("0" & item 4 of it) & char -1 of ("0" & item 4 of it) &&\
":" & char -2 of ("0" & item 5 of it) & char -1 of ("0" & item 5 of it)
end mouseUp
Colin?
Re: Format Current DateTime to 2011 02 01 03:04 ?
dunbarx...
Lovely...
be well
Dixie
Lovely...

be well
Dixie
Re: Format Current DateTime to 2011 02 01 03:04 ?
Hi all,
me too!
Best from sunny germany
Klaus
me too!

Code: Select all
...
put the seconds into tNow
convert tNow to dateItems
answer item 1 of tNow && format("%02d",item 2 of tNow) && format("%02d",item 3 of tNow) && \
format("%02d",item 4 of tNow) & ":" & format("%02d",item 5 of tNow)
...

Best from sunny germany
Klaus
-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Re: Format Current DateTime to 2011 02 01 03:04 ?
Decided on this routine
as it's easier to read
and should be super easy to convert to a funtion with multiple formats.
Well for me anyway.
[/size]
as it's easier to read
and should be super easy to convert to a funtion with multiple formats.
Well for me anyway.
Code: Select all
on mouseUp
put the seconds into tNow
convert tNow to dateItems
-- dateItems: 2000,2,17,22,13,21,5
-- dateItems: Year, Month, Day, Hour, Minute, Second, Day of week
put item 1 of tNow into tStamp
repeat with x = 2 to 5
if x < 5 then
put " " after tStamp
else
put ":" after tStamp
end if
Put format("%02d",item x of tNow) after tStamp
end repeat
Answer tStamp
end mouseUp
All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
-
- Posts: 1201
- Joined: Sun Apr 24, 2011 2:17 am
Re: Format Current DateTime to 2011 02 01 03:04 ?
well that was nice n handy. 

All my best,
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.
Barry G. Sumpter
Deving on WinXP sp3-32 bit. LC 5.5 Professional Build 1477
Android/iOS/Server Add Ons. OmegaBundle 2011 value ROCKS!
2 HTC HD2 Latest DorimanX Roms
Might have to reconsider LiveCode iOS Developer Program.