# Help with powershell code

**URL:** <https://forums.powershell.org/t/help-with-powershell-code/14883>\
**Category:** PowerShell Help\
**Created:** [September 1, 2020, 10:28am UTC](https://forums.powershell.org/t/help-with-powershell-code/14883 "2020-09-01T10:28:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![acio](https://avatars.discourse-cdn.com/v4/letter/a/ecae2f/32.png) [@acio](https://forums.powershell.org/u/acio)\
**Post date:** [September 1, 2020, 10:28am UTC](https://forums.powershell.org/t/help-with-powershell-code/14883/1 "2020-09-01T10:28:19Z")

</div>

Hello everyone, I have a csv file I got from exporting data from a sql database. There are 2 columns, with 1 of them being dates/times and the other a number. When i open the file in Excel the date and time is not formatted, the default formatting for the row containing the date/time shows up as Number –\> Custom –\> mm:ss.0. I have to select the whole column and change formatting to Date –\> mm/dd/yyyy hh:mm.

Is there any way to automate the process using powershell and if so can you please provide the code? filename is test.csv and the rows do not have a header, they are row #1 and #2

thank you in advance

&nbsp;

thank you in advance

---

<div class="post-metadata">

**Author:** ![grokkit](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/grokkit/32/970_2.png) [@grokkit](https://forums.powershell.org/u/grokkit)\
**Post date:** [September 1, 2020, 10:53am UTC](https://forums.powershell.org/t/help-with-powershell-code/14883/2 "2020-09-01T10:53:41Z")

</div>

> [@](#):
>
> Is there any way to automate the process using powershell

Yes, it’s possible to manipulate csv and Excel files with PowerShell. However, for this relatively minor action it might not be worth the time to create and troubleshoot a script unless you are handling a lot of files. It might also be easier to manipulate the date/time value in PowerShell so that it is automatically recognized as a date/time by Excel, and _then_ import the data into Excel, rather than trying to change the data format in Excel after importing.

> [@](#):
>
> and if so can you please provide the code?

No. This is a help & troubleshooting forum, not a “do my job for me” forum. People get paid for the kind of work you’re asking for.

---

<div class="post-metadata">

**Author:** ![rob-simmers](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/rob-simmers/32/1010_2.png) [@rob-simmers](https://forums.powershell.org/u/rob-simmers)\
**Post date:** [September 1, 2020, 2:13pm UTC](https://forums.powershell.org/t/help-with-powershell-code/14883/3 "2020-09-01T14:13:48Z")

</div>

A much simpler approach is to just do the sql query with Powershell so there is no need to do anything with the dates. Using the SQL module installed with SQL Management Studio is the simplest, but this list has the many ways you can interact with SQL:

> **[The PoSh DBA: Accessing SQL Server from PowerShell - Simple Talk](https://www.red-gate.com/simple-talk/databases/sql-server/database-administration-sql-server/the-posh-dba-accessing-sql-server-from-powershell/)**
>
> The worst part for a DBA of getting started with PowerShell is often just figuring out the best way of working with SQL Server. The most suitable approach to accessing SQL Server depends on the sort of task you need to produce a script for. Laerte...

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:29pm UTC](https://forums.powershell.org/t/help-with-powershell-code/14883/4 "2024-05-16T20:29:00Z")

</div>


