Sending the correct time to DatePicker in PHP?

Hello, i’m trying to figure out how to send a time stamp correctly to a datepicker property. I’ve done some research on here but can’t really find a answer.

Here’s what I got:

$time = 1632182399;

I had did some research and found a contributor had suggested this solution: https://community.hubspot.com/t5/APIs-Integrations/Update-Custom-Date-Picker-in-Deals-through-the-API/m-p/229499

But this doesn’t actually work and I don’t know why. Perhaps I’m calling it wrong? This is what I was trying:

function get_time_for_hubspot($time){
 $date = new DateTime();
 $date->setTimestamp($time);
 return gmdate('Y-m-d H:i:s', strtotime($date->format('Y-m-d H:i:s')));
}

// Time Stamps $starttime = strval($booking_object->start); $endtime = strval($booking_object->end); $starttime = get_time_for_hubspot($starttime); $endtime = get_time_for_hubspot($endtime);

Which produces:
$starttime = 2021-09-13 00:00:00
$endtime = 2021-09-13 23:59:59

Thanks for any help.

@TLane

Make sure you send your timestamp in milliseconds. You are a few digits shy there :grinning_face:

$time = 1632182399; should be

$time = 1646945881755

Thanks Dennis. Are you supposed to send the time as just the milliseconds or are you supposed to convert it to UTC and send that?

Nope. Just send as a unix timestamp in mills

Hmm okay. Do you by chance know the logic i’d use to convert that to a unix timestamp in mills in PHP ? :V Its the one thing I can’t seem to figure out correctly!