Skip to content

Instantly share code, notes, and snippets.

@fsans
Last active October 6, 2022 16:40
Show Gist options
  • Save fsans/9b6a2b233b48884dfbbca0db7ca18871 to your computer and use it in GitHub Desktop.
Save fsans/9b6a2b233b48884dfbbca0db7ca18871 to your computer and use it in GitHub Desktop.
Format FileMaker Date or Time to SQL92 syntax

SQL92Date(fmdate)

Let(
[
    _year = Right( "0000" & Year( fmdate ); 4 );
    _month = Right( "00" & Month( fmdate ); 2);
    _day = Right( "00" & Day( fmdate ); 2)
];

    Case( IsEmpty( fmdate ); ""; "DATE " & SQLquote( Join( List( _year;_month;_day ); "-") ) )

)

/*
fmdate as '2019-06-05'
SQL92Date(get(CurrentDate)) -> DATE '2022-10-06'
 
by air.fsans@gmail.com 2022
dependencies:
    Join(fmlist, delim)
*/

SQL92Time(fmtime)

Let(
[
    _hour = Right( "00" & Hour ( fmtime ); 2);
    _minute = Right( "00" & Minute ( fmtime ); 2);
    _second = Right( "00" & Seconds ( fmtime ); 2)
];

    Case( IsEmpty( fmtime ); ""; "TIME " & SQLquote ( Join( List( _hour; _minute; _second); ": ") ) 
)

/* 
fmtime as 'HH:MM:SS' 
SQL92Time( get( CurrentTime ) ) -> TIME '18:08:57'

by air.fsans@gmail.com 2022
dependencies:
    Split(str, delim)
    Join(fmlist, delim)
*/

TIMESTAMP formating

For Timestamp functions see this newest CF here (requires FM v19.5): SQL92Timestamp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment