LoginSignup
0
1

More than 3 years have passed since last update.

2016-03-28 c++ builder XE4, 10.2 Tokyo | datetime > 時分秒をTDateTime型から取り除く

Last updated at Posted at 2016-03-28
動作環境
C++ Builder XE4
Rad Studio 10.2 Tokyo Update 2 (追記: 2017/12/27)

やりたいこと

TDateTimeで与えられた日時情報から時分秒を00にしたい。
ある指定日の0時からの処理をしたいときなどに使う。

code

DecodeDate()とEncodeDate()を使う方法を実装した。

static TDateTime __fastcall getDayWithoutTime(TDateTime srcdt)
{
    unsigned short yyyy,mm,dd;
    DecodeDate(srcdt,yyyy,mm,dd);
    TDateTime resdt = EncodeDate(yyyy,mm,dd);

    return resdt;
}

code v0.2

(追記 2016/07/07)

TDateTime型の小数部分を消せばいいだけなので、以下でも可能だった。

static TDateTime __fastcall getDayWithoutTime(TDateTime srcdt)
{
    return (TDateTime)(int)srcdt;
}
0
1
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
0
1