Time_ofDay ( _var )
return number of seconds since midnight if valid or nothing if invalid
Average rating: 3.9 (44 votes) Log in to vote
Rewolfer - Show more from this author
http://rewolfer.de |
Time_ofDay ( "11:01:13 PM")
Function definition: (Copy & paste into FileMaker's Edit Custom Function window)
/*=[Time_ofDay]=[2.10]===================================
FORM:
Time_ofDay ( _var )
PURPOSE:
return number of seconds since midnight if valid or NOTHING if invalid
PARAMETER:
_var format: unknown value:variable
RESULT:
number of seconds since midnight if valid or NOTHING if invalid
DEPENDENCY:
-
NOTE:
check with IsEmpty ( Time_OfDay ( _var )) instead of GetAsBoolean ( Time_OfDay ( _var )) since Time_OfDay ( 0:0 ) is valid
valid Time_ofDay: 17:09:56 / 17:9:56 / 5:9 PM / 5:09 p.m. / not 170956 / not 123:34
tolerates whitespace
accepts AM/PM notation
see my other function Time_Value ( _var )
EXAMPLE:
Time_ofDay ( "23:1:13" ) => 82873
Time_ofDay ( "11:10:13 PM" ) => 82873
Time_ofDay ( "26:30" ) => ""
HISTORY:
2012-04-13 [235325] 1.00 tsw turned into IsTimeOfDay() to be valid in #VarType
2012-04-26 [005836] 1.10 tsw integrated AM/PM
2015-09-01 [110300] 2.00 tsw renamed to Time_ofDay to better reflect expected output
2018-01-31 [100000] 2.10 tsw AM/PM-correction
DEVELOPER:
tsw @ http://rewolfer.de
=================================================*/
Let ([
_var = Trim ( _var );
_sliceSpace = Substitute ( _var ; " " ; ¶ );
_time = GetValue ( _sliceSpace ; 1 ) ;
_ampm = Lower ( GetValue ( _sliceSpace ; 2 )) ;
_isAMPM = Case (
_ampm = "pm" or _ampm = "p.m." ; 12 ;
Left ( _var ; 3 ) = "12:" and ( _ampm = "am" or _ampm = "a.m." ); 12 );
_colonCount = PatternCount ( _var ; ":" );
_clean = Filter ( _time ; "0123456789¶:" )
];
Case (
_clean = _time and ( _colonCount = 1 or _colonCount = 2 );
Let ([
_e = Substitute ( _time ; ":" ; ¶ );
_hh = GetAsNumber ( GetValue ( _e ; 1 ));
_hh = Case ( _hh = 12 ; _hh - _isAMPM ; _hh + _isAMPM );
_mm = GetAsNumber ( GetValue ( _e ; 2 ));
_ss = GetAsNumber ( GetValue ( _e ; 3 ))
];
Case (
not IsEmpty ( _hh ) and not IsEmpty ( _mm ) and ( 24 > _hh ) and ( 60 > _mm ) and ( 60 > _ss ) ; GetAsNumber ( Time ( _hh ; _mm ; _ss ))
)
)
)
)
Comments
Dean Suhr, MLD Foundation Jun 7, 2020 |
||
This script works great with am & pm, but not with AM & PM. I suggest changing the second line of the script to _var = Lower( Trim ( _var )); |
||
Rewolfer Jun 10, 2020 |
||
Hello Dean, I noticed this myself 2 years ago (never use AM/PM here in Germany ;-) but hadn't updated the CF on this platform. So here comes the new version. Thanks for your comment, Rewolfer. |
||
Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.