Converting datetime to int

Reply

Join Date: Sep 2006
Posts: 90
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Converting datetime to int

 
0
  #1
Mar 30th, 2009
This set of code below shows all SQL Server Agent jobs that have failed for the date 200.03.29. The run_date column is an integer, but I want to run the code in such a way that the resultset is automatically generated for the day before the current date.

The code that works is below:

  1. SELECT [name] AS [Job Name],[server] AS [Server], step_id, step_name, [message] AS [Error],
  2. run_date AS [Date Started], run_time AS [Time Started], run_duration AS [Duration]
  3. FROM sysjobs JOIN sysjobhistory ON sysjobs.job_id = sysjobhistory.job_id
  4. WHERE run_date = 20090329
  5. AND run_status = 0

How can I change this so that run_date will get the equivalent integer value representing the day before the current date?
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 1
Reputation: squarefish is an unknown quantity at this point 
Solved Threads: 0
squarefish squarefish is offline Offline
Newbie Poster

Re: Converting datetime to int

 
0
  #2
Mar 31st, 2009
CONVERT (varchar, GETDATE() - 1, 112) will give you yesterdays date in that format
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 90
Reputation: bajanpoet is an unknown quantity at this point 
Solved Threads: 0
bajanpoet bajanpoet is offline Offline
Junior Poster in Training

Re: Converting datetime to int

 
0
  #3
Mar 31st, 2009
Originally Posted by squarefish View Post
CONVERT (varchar, GETDATE() - 1, 112) will give you yesterdays date in that format

Thanks, but I wanted it as an INTEGER, not a varchar... the script references the sysjobhistory table in the msdb database, and, in that table, the run_date column is an integer.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the MS SQL Forum


Views: 1491 | Replies: 2
Thread Tools Search this Thread



Tag cloud for MS SQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC