Monday, March 19, 2012

Need script help w/ dates

Hi,

I have a script where I retrieve the date portion of a filename into an integer variable.

The variable value looks like this: "20070815"

My question is, how can I then take this value and compare it against the current date on the server? Is there any sample code that can show me how to use date functions in this way?

Thanks

You should be able to direclty compare in the query.Something like this for example.

IF GETDATE() > '20070815'

BEGIN

PRINT 'More'

END

<edit>

In query it would be like

select col1,col2 from tbla where dt_col > '20070815'

</edit>

Thanks

|||In your script, you can do:

Dim todaysDate As String = DateTime.Now.ToString("yyyyMMdd")

Then you can just compare to your input date.|||I noticed you said "integer" variable above. If so, then this should work:

Dim todaysDate as Integer = CInt(DateTime.Now.ToString("yyyyMMdd"))|||

Thanks Phil. This should do the trick.

No comments:

Post a Comment