Format Filter Date/Time Deserialization Issue

Hello, as we know, octopus deserializes dates and we must use the format filter to prevent the date from changing. However, when I run the below code:

$body = @{
  "name" = $Schedule;
  "version" = $Version;
  "start" = "#{StartTime | Format "yyyy-MM-ddThh:mm:ss.000"}";
  "end" = "#{EndTime | Format "yyyy-MM-ddThh:mm:ss.000"}";

$bodyJson = ConvertTo-Json $body
Write-Host $bodyJson

Write-Host $StartTime
Write-Host $EndTime

The output is correct when the variable(s) are written ($StartTime, $EndTime) but it is wrong in the body.

See Output (end and start are the same value when the variable output writes the correct, different values) :

    "end":  "2023-05-17T08:00:00.000", 
    "name":  "Caleb Test Open", 
    "version":  null, 
    "start":  "2023-05-17T08:00:00.000" 
05/17/2023 08:00:00 
05/17/2023 20:00:00

Any thoughts on what I’m missing here? Thanks in advance!

Hi @casmith,

Thanks for getting in touch, and I appreciate your report! I agree this is unexpected, and I’ve reproduced what looks to likely be the issue you’re hitting as well, which I’d like to bring up internally for further discussion.

The issue I’m seeing is this is being treated as a 12 hour clock instead of the expected 24 hours, which is quite misleading. Where in your case 20:00:00 which is what you’re expecting is 8 PM but it should certainly output with 20:00:00.000 as you were also expecting.

One potential workaround is to use tt in the format filter expression to output AM/PM which hopefully helps avoid some confusion here. E.g. "end" = "#{EndTime | Format "yyyy-MM-ddThh:mm:ss tt"}";, but that is definitely not ideal still.

I’ll keep you updated with any and all input, and let me know if you have any further questions or concerns.

Best regards,


Hey Kenneth,

I appreciate you taking a look! Is this something that would be resolved in a future release? I would use the tt recommendation but the API we’re communicating with can’t consume that.


Hi Caleb,

Thanks for getting back here! I’m just stepping in for Kenny as he’s offline today. One of our team members pointed out that the issue could be related to the hh part of the date time string. The following Microsoft docs suggest that capitalizing the HH formats the string into the 24 hour format.

So the following should correctly evaluate to desired 24 hour format:

$body = @{
  "name" = $Schedule;
  "version" = $Version;
  "start" = "#{StartTime | Format "yyyy-MM-ddTHH:mm:ss.000"}";
  "end" = "#{EndTime | Format "yyyy-MM-ddTHH:mm:ss.000"}";

Let us know if that helps or if you have any further questions or thoughts at all.

Best regards,

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.