CSV ignoring '0' This topic contains 7 replies, has 4 voices, and was last updated by Olaf Soyk 1 year, 4 months ago. Author Posts November 10, 2016 at 7:05 pm #57368 Tony AntonyParticipant Hello, I have a CSV file that contains date 2016-11-10 00:00:00, the problem is that, it's ignoring the 0 on the day (10 $Date_Effective = ($Import_CSV."Date Effective").Trim(" 00:00:00") It's reading 2016-11-10 as 2016-11-1 It was working fine yesterday since yesterday was 2016-11-09 Thank you, Tony November 10, 2016 at 7:18 pm #57370 Olaf SoykParticipant try this: $Date_Effective = ($Import_CSV."Date Effective").Trim("00:00:00").Trim() ... works for me November 10, 2016 at 7:22 pm #57374 Tony AntonyParticipant Thank you Olaf Soyk, that worked. I know the second Trim() is to trim the 00:00:00, but how does the first Trim() work? November 10, 2016 at 9:54 pm #57389 Olaf SoykParticipant Of course Robs recommendation is always the best way. But to answer your question you can do this: "'$('2016-11-10 00:00:00'.Trim('00:00:00'))'" The Result will be '2016-11-10 '. There's still a trailing space. That's what the second Trim() removes: "'$('2016-11-10 '.Trim())'" The result will now be '2016-11-10' November 10, 2016 at 7:40 pm #57377 Rob SimmersParticipant I would highly recommend if you are working with Dates to work with them as a date versus a string. Rather than trying to manipulate the string with Trims or replaces, convert it to a date and then you can format it however you want: $date_as_string = "2016-11-10 00:00:00" Get-Date $date_as_string -Format d #or Get-Date $date_as_string -Format "yyyy/MM/dd" Output: 11/10/2016 2016/11/10 November 10, 2016 at 7:42 pm #57379 Tony AntonyParticipant Thank you Rob November 10, 2016 at 10:52 pm #57394 Tim CurwickParticipant Tony, I often wish .Trim() worked like that, but it doesn't. $DateString.Trim( ' 00:00:00' ) is going to trim all spaces, colons and zeros that appear at the beginning and end of the string in any order. The are many ways you could do what you want; I would probably do this: $DateString.Split( ' ' ) November 11, 2016 at 12:28 am #57395 Olaf SoykParticipant Tim, wow ... cool ... thanks ... now I really understand how the trim() operator works. So if we would like to accomplish the task with the same approach we could even make it a little shorter: "'$('2016-11-10 00:00:00'.Trim('0:').trim())'" Author Posts You must be logged in to reply to this topic.