Look at the below code. One is working with $var.ToString() comparing, other without it is not working. Is there any unsaid logic behind the scenes.? 11/28/2018 is date today. I tried using [datetime] in front of variables and it didnt make any difference.
In the first situation, I’m guessing the objects aren’t exactly alike. Dates generated that way can get a little weird, honestly. A proper DateTime object has sub-second resolution, which you’re not accounting for (and which normally wouldn’t display).
In the second, you’re not comparing dates. You’re comparing literal strings. ToString() is what’s used to display a DateTime object on-screen, and it ignores sub-second resolution, so you’re kind of “equalizing” the two objects by doing that.
Yes I figured out that milliseconds is hidden… I fixed it by using -format d…
I couldn’t update the comment since the post was waiting for moderator. I am excited talking to you Don Jones. Your book learn powershell in a month is an inspiration. It made me write code from one line commands to thousands lines of scripts …
But I have a question… Why Microsoft is not building Excel modules so far while Doug Finke has been doing it with ImportExcel and I understand Epplus.dll is open source. I am sure Ms can use their own interoperability or excel core. Just wondering if you have any answers already
As Don says, there’s more data there you’re going to have a bit of difficulty excluding in this manner. DateTime lets you retrieve just the Date you want to check for, though, which can be neatly compared in the same way:
The last time MS invested in Office Automation was in 2010, I think. It’s just not where they want to spend their time and money. Even then, they just put a thin .NET wrapper around the 2003-era COM stuff. Fortunately, guys like Doug do a great job.
Thanks. However , not all organizations allow to install modules from untrusted repository . That’s why I was hoping Ms would come up with their own . Sadly, seems we have to wait . Anyways, thank you very much for the responses. I have been watching your pluralsight videos too . Just read your about me webpage. You are a great personality.
Keep it up… Will catch up if powershell wants me to put another QnA