0

I have an event receiver in sharepoint online and it is deployed in azure. so i noticed that it is returning the wrong date and have noticed that it gets the previous day if the time is 12:00AM. example i have this in my sp list

enter image description here

but when i try to check and log in the event receiver it is giving me this even if i only print attributes[FIELD_NG_EVENTDATE] without converting it is giving me this:

DATES: 2/28/2019 4:00:00 PM - 3/1/2019 3:59:59 PM 2019-02-28T16:00:00Z

this is what the code lookslike in the event receiver, i have already added the code to convert the dates but the issue is still the same. :

var attributes = properties.ItemEventProperties.AfterProperties;
 DateTime startDateUTC = Convert.ToDateTime(attributes[FIELD_NG_EVENTDATE]);

            DateTime endDateUTC = Convert.ToDateTime(attributes[FIELD_NG_ENDDATE]);

            DateTime startDateLocal = Convert.ToDateTime(Convert.ToString(startDateUTC.ToLocalTime()));

            DateTime endDateLocal = Convert.ToDateTime(Convert.ToString(endDateUTC.ToLocalTime()));

            AddEventLogItem(clientContext, "GetDetails DATES:  ", attributes[FIELD_NG_EVENTDATE] + " converted: " + startDateLocal + " - " + endDateLocal + " " + attributes[FIELD_NG_EVENTDATE] );

            switch (properties.EventType)
            {
                case SPRemoteEventType.ItemAdding:
                    return new BookingDetail(attributes[FIELD_NG_VENUES], startDateLocal,
                        endDateLocal, IsChecking, VenueID, string.Empty, eventType);
                case SPRemoteEventType.ItemUpdating:
                    return GetBookingDetailForItemUpdating(clientContext, properties);
            }

this is the class:

 public class BookingDetail
{
    public List<int> Venues;
    public DateTime StartDate;
    public DateTime EndDate;
    public string EventType;
    //Added by NG 06/11/2017
    public bool IsChecking;
    public string VenueID;
    public string BookingStatus;
    public int ID;
    public int EventBookingId; //Added on 17Sep2018
    //End


    public BookingDetail(object venues,
                         object startDate,
                         object endDate,
                         object ischecking,
                         string venueID,
                         string bookingStatus,
                         string eventType = null,
                         int id = 0,
                         int eventBookingId = 0)
    {
        Venues = Utils.ConvertLookUpIdStringToList(venues.ToString());

        StartDate = Convert.ToDateTime(startDate);
        EndDate = Convert.ToDateTime(endDate);
        EventType = eventType ?? null;
        IsChecking = Convert.ToBoolean(ischecking);
        VenueID = venueID;
        BookingStatus = bookingStatus;
        ID = id;
        EventBookingId = eventBookingId;
    }
}
0

Write endDateUTC, endDateUTC.ToLocalTime(), Convert.ToString(startDateUTC.ToLocalTime()), and Convert.ToDateTime(Convert.ToString(endDateUTC.ToLocalTime())) each to the log. It seems likely that one of those transformations is where you're jumping the tracks. And its possibly related to your time zone. Are you in the Pacific time zone by any chance? (i.e. UTC-8)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.