Search code examples
c#castingbloomberg

How do I cast a Bloomberg DateTime to System.DateTime


What is the preferred way to cast a BBG DateTime to normal System?

DateTime px_close_dt = (DateTime) fields.GetElementAsDatetime("PX_CLOSE_DT");

Bloomberglp.Blpapi.DateTime is returned...

This gives cast error


Solution

  • You need to use the method ToSystemDateTime(); like:

    DateTime px_close_dt = fields.GetElementAsDatetime("PX_CLOSE_DT").ToSystemDateTime();
    

    See: DateTime.ToSystemDateTime

    Converts this BLP Datetime object into System.DateTime object.