I have a PowerShell script that executes perfectly locally via VS Code, but when I deploy it to an Azure Function it fails.
The code in question is as follows:
$creation_date = $item.date.SubString(0,10)
$parsedDate = [DateTime]::ParseExact($creation_date, 'yyyy-MM-dd', $null)
When I run it locally, I receive the following output
2023-12-04
04/12/2023 12:00:00 AM
When I run it as an Azure Function, I get the following error
ERROR: Method invocation failed because [System.DateTime] does not contain a method named 'Substring'. Exception : Type : System.Management.Automation.RuntimeException ErrorRecord : Exception : Type :System.Management.Automation.ParentContainsErrorRecordException Message : Method invocation failed because [System.DateTime] does not contain a method named 'Substring'. HResult : -2146233087 CategoryInfo : InvalidOperation: (:) [], ParentContainsErrorRecordException FullyQualifiedErrorId : MethodNotFound InvocationInfo : ScriptLineNumber : 68 OffsetInLine : 1 HistoryId : -1 ScriptName : C:\home\site\wwwroot\TimerTrigger1\run.ps1 Line : $creation_date = $item.date.Substring(0,10) PositionMessage : At C:\home\site\wwwroot\TimerTrigger1\run.ps1:68 char:1 + $creation_date = $item.date.Substring(0,10) +
From VS Code, I am executing the script in PowerShell Core 7.3.10
In Azure Functions, my runtime stack is shown as PowerShell - 7.2
I'm assuming that there is a runtime incompatibility, but I'm unsure where to head next. Any advice would be greatly appreciated.

$item? Try:$item.date.ToString().SubString(0,10)[DateTime]::ParseExactsets the format/culture provider but as you apparently have different cultures and$item.dateis probably already a[date]type (what is:$item.date.GetType()?), I would just let the PowerShell Get-Date cmdlet figure it out:get-date '12/5/2023'<=>get-date '2023-12-05'