LoginSignup
3
3

More than 5 years have passed since last update.

【FileMaker】日付をファイル名に入れたい、そしてゼロ詰め

Posted at

よくあるお題です。
今回のこのやり方が効率いいのかよくわかりませんが、人に聞かれたら、以下を紹介しています。

(例)年下2桁で日付をテキストでもちたい。ゼロ詰め、よろしく。
「2016年5月11日」→「160511」

方法1

Let ( [
$sampledate = Get(日付)
] ; 
Right(Year($sampledate);2) & 
If ( Length(Month($sampledate))>1 ; Month($sampledate) ; "0" & Month($sampledate) ) & 
If(Length(Day($sampledate))>1;Day($sampledate);"0" & Day($sampledate) )
)

方法2

Let ( [
$sampledate = Get(日付)
] ; 
Right(Year($sampledate);2) & 
Right("0" & Month($sampledate);2) & 
Right("0" & Day($sampledate);2) 
)

これ↑を変数なり計算フィールドなりに指定すればOKです。

どっちかっていうと、方法2の方がすっきりしていますよね。
方法1は、すっきり感がないということに付け加えて、同じ関数を複数回使ってます。(Month,Day関数)
同じ関数を使うよりも、処理速度のことも考えてなるべく少なく実装できると「おれって深いい」と自負できます。(ほんとか?)
今回の例みたいのは処理速度なんて気にしなくて全然OKですが、何かしら頭の中で分岐がでてきたら、分岐しなくても実装できる方法を考えてみてもいいですね。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3