Dec 302011
 

So I just created a query that will get today’s date dynamically from the database itself, but I’m sure there must be a simpler way of doing it.
the query I’m using now is :


SELECT
count(Incident_ID)
FROM
INCIDENTSM1
WHERE TITLE = 'Password Reset - Windows Login'
AND
CLOSE_TIME > CAST(DATEPART(year,GetDate()) as varchar)+'-'+CAST(DatePart(month,getdate()) as varchar)+'-'+CAST(DatePart(day,getdate()) as varchar)

Just thought I’d throw this out there in case anyone else needs to do something similar in Microsoft SQL.
If anyone has any suggestions on how to improve that query, feel free to post them in the comments.

Share
Dec 292011
 

So I’ve recently been playing around with Powershell to do some scripts at work, and ran into this hurdle.
I had to get today’s date, minus 2 days from it, and then output it in a certain format.
After much mucking about, I finally found out how to do it.

Firstly, assign the date to a variable

$a = Get-Date

And then, I can subtract the days I need and format it at the same time, and assign it to the second variable.

$b = $a.AddDays(-2).toString("yyyy/MM/dd hh:mm")

And voila, I now have the date minus 2 days in the format I need.

2011/17/27 11:17

Share