2

I need to convert DateTime type to Date. here is my code:

DateTime dt = DateTime(2015, 1, 1, 14, 10, 13);
Date z = cast(Date)dt;

Error: cannot cast from DateTime to Date

Whats wrong?

Adrian Leonhard
  • 7,040
  • 2
  • 24
  • 38
Suliman
  • 1,469
  • 3
  • 13
  • 19

1 Answers1

5

DateTime isn't a Date, you can't cast it. To convert, simply access the DateTime.date() property:

http://dlang.org/phobos/std_datetime.html#.DateTime.date

const pure nothrow @property @safe Date date();

The date portion of DateTime.
Community
  • 1
  • 1
Adrian Leonhard
  • 7,040
  • 2
  • 24
  • 38