Skip to content

Import-DbaCsv converts date to wrong datetime #10338

@stephantroxler

Description

@stephantroxler

Verified issue does not already exist?

I have searched and found no existing issue

What error did you receive?

When importing a CSV with "de-ch" format dates, the month and day are in wrong order if below 12.

I have CSVs with datetime fields in "de-ch" style: "01.05.2026 12:00:00" that I want to import to a smalldatetime field in a DB with "Latin1_General_CI_AS". Up until ~dbatools 2.7.7 I was able to do this without additional parameters or formatting. With the new CSV library the cmdlet can't read those dates anymore and throws an error "Failure | CSV parse error". I then figured out it imports the data by adding -Culture "de-ch". Some dates however end up with switched month/day:

May 1th > "01.05.2026 12:00:00" -> "2026-01-05" (wrong, correct "2026-05-01")

Steps to Reproduce

#test.csv
"Date1";"Date2"
"02.04.2026 17:09:41";"14.04.2026 17:09:41"
"11.06.2026 17:10:08";"13.06.2026 06:22:23"

#Table
CREATE TABLE [dbo].[test](
[Date1] [smalldatetime] NULL,
[Date2] [smalldatetime] NULL
)

Import-DbaCsv -Path ".\test.csv" -SqlInstance -Database -Table "test" -Culture "de-ch"

---- Output ----
SELECT * FROM test

Date1 Date2
2026-02-04 17:10:00 2026-04-14 17:10:00
2026-11-06 17:10:00 2026-06-13 06:22:00

Please confirm that you are running the most recent version of dbatools

2.7.27 dbatools
2025.12.28 dbatools.library

Other details or mentions

It would be great to have the behaviour back from version 2.7.7 where the cmdlet discovered the datetime format automatically without mentioning the culture.

What PowerShell host was used when producing this error

Windows PowerShell (powershell.exe)

PowerShell Host Version

5.1

SQL Server Edition and Build number

Microsoft SQL Server 2022 (RTM-CU21) (KB5065865) - 16.0.4215.2 (X64)
Aug 11 2025 13:24:21
Copyright (C) 2022 Microsoft Corporation
Developer Edition (64-bit) on Windows Server 2016 Standard 10.0 (Build 14393: ) (Hypervisor)

.NET Framework Version

.NET Framework 4.8.4795.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugs lifetriage requiredNew issue that has not been reviewed by maintainers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions