1answers

Format a date when not in layout mode?

Does FileMaker have a function that can format a date the way you would like? The one in the Inspector is like what I am talking about. Or do you have to write one yourself?

I have a date in one of my calculations that leaves off leading zeros on days and months I want:

9/2/2013 to be 09/02/2013

Are there any documents by FileMaker that show functions and formatting like dd = 09 YYYY = 2013?

Chris Johnston

Answers

While FileMaker allows you to visually format a date on a layout, you must format the result of your calculations yourself.

It's important to note that FileMaker stores date and time values as integers within the database. That being said, if your calculation result is set to DATE and you format it to suit your particular needs, the output will be a "?" (error).

The trick is to set the calculation result to TEXT.


Here's a calculation that I wrote years ago to format a date.

I hope that you find it useful!

Let (

// This calculation formats the current time.

[ // BEGIN the declaration of variables.

// Capture the TimeStamp into individual variables.

TS = Get ( CurrentHostTimeStamp ) ;

Y = Year ( TS ) ;

M = Month ( TS ) ;

D = Day ( TS ) ;

H = Hour ( TS ) ;

Min = Minute ( TS ) ;

Sec = Seconds ( TS ) ;

// Format the TimeStamp variables to equal "lengths".

fM = Case ( M < 10 ; "0" & M ; M ) ;

fD = Case ( D < 10 ; "0" & D ; D ) ;

fH = Case ( H < 10 ; "0" & H ; H ) ;

fMin = Case ( Min < 10 ; "0" & Min ; Min ) ;

fSec = Case ( Sec < 10 ; "0" & Sec ; Sec )

] ; // END the declaration of variables.

// Reassemble the TimeStamp for output.

Y & "." & fM & "." & fD & "." & fH & fMin & "." & fSec )

Kevin Kurpe

Unbeleivable again! Thanks

Back to questions