public static DataTable ReportsCityFilter(DateTime dtStart, DateTime dtEnd)
{
//Dictionary<DateTime.TryParse((string DateString, IFormatProvider provider, System.Globalization.DateTimeStyles styles, "ddMMyyyy"), object> objDic = new Dictionary<DateTime, object>();
Dictionary<string, object> objDic = new Dictionary<string, object>();
objDic.Add("@start_date", dtStart);
objDic.Add("@end_date", dtEnd);
return dal.execute(objDic, "sp_admin_reports_city_filter_select").Tables[0];
}
i have a page on which i have report by city, now i added a dropdown on it to filter results by date i.e. week, today, month, year etc
everything else is working, but there is something wrong with this piece of code becasue its giving me error "Conversion failed when converting date and/or time from character string."
P.S. this is my stored procedure
ALTER PROCEDURE [dbo].[sp_admin_reports_city_filter_select] -- Add the parameters for the stored procedure here --@id INT = NULL @start_date DateTime , @end_date DateTime AS BEGIN --declare @startdate datetime set @start_date = '2999-01-01'
if @start_date = 'today'
begin
select jp.id, city.name[City]
, row_number() over (order by city.name) [sr_no]
, count(jp.id) over (partition by name) as no_of_posts
, COUNT(od.id) over (partition by name) as no_of_employers
,CONVERT(varchar(12), jp.posting_date, 103) [date_created]
from rs_job_posting jp
inner join rs_job_posting_location jpl on jpl.id = jp.id
inner join rs_cor_city city on city.id = jpl.city_fk
inner join rs_organization_detail od on od.id = jp.id
where DAY(posting_date) = DAY(GETDATE())
order by no_of_posts Desc
select jp.date_updated
from rs_job_posting jp
END
else if @start_date = 'weekly'
begin
select jp.id, city.name[City]
, row_number() over (order by city.name) [sr_no]
, count(jp.id) over (partition by name) as no_of_posts
, COUNT(od.id) over (partition by name) as no_of_employers
,CONVERT(varchar(12), jp.posting_date, 103) [date_created]
from rs_job_posting jp
inner join rs_job_posting_location jpl on jpl.id = jp.id
inner join rs_cor_city city on city.id = jpl.city_fk
inner join rs_organization_detail od on od.id = jp.id
where DAY(posting_date) = DAY(GETDATE())
order by no_of_posts Desc
select jp.date_updated
from rs_job_posting jp
end
else if @start_date = 'byweekly'
begin
select jp.id, city.name[City]
, row_number() over (order by city.name) [sr_no]
, count(jp.id) over (partition by name) as no_of_posts
, COUNT(od.id) over (partition by name) as no_of_employers
,CONVERT(varchar(12), jp.posting_date, 103) [date_created]
from rs_job_posting jp
inner join rs_job_posting_location jpl on jpl.id = jp.id
inner join rs_cor_city city on city.id = jpl.city_fk
inner join rs_organization_detail od on od.id = jp.id
where DAY(posting_date) = DAY(GETDATE())
order by no_of_posts Desc
select jp.date_updated
from rs_job_posting jp
end
else if @start_date = 'monthly'
begin
select jp.id, city.name[City]
, row_number() over (order by city.name) [sr_no]
, count(jp.id) over (partition by name) as no_of_posts
, COUNT(od.id) over (partition by name) as no_of_employers
,CONVERT(varchar(12), jp.posting_date, 103) [date_created]
from rs_job_posting jp
inner join rs_job_posting_location jpl on jpl.id = jp.id
inner join rs_cor_city city on city.id = jpl.city_fk
inner join rs_organization_detail od on od.id = jp.id
where DAY(posting_date) = DAY(GETDATE())
order by no_of_posts Desc
select jp.date_updated
from rs_job_posting jp
end
else if @start_date = 'yearly'
begin
select jp.id, city.name[City]
, row_number() over (order by city.name) [sr_no]
, count(jp.id) over (partition by name) as no_of_posts
, COUNT(od.id) over (partition by name) as no_of_employers
,CONVERT(varchar(12), jp.posting_date, 103) [date_created]
from rs_job_posting jp
inner join rs_job_posting_location jpl on jpl.id = jp.id
inner join rs_cor_city city on city.id = jpl.city_fk
inner join rs_organization_detail od on od.id = jp.id
where DAY(posting_date) = DAY(GETDATE())
order by no_of_posts Desc
select jp.date_updated
from rs_job_posting jp
end
end
sp_admin_reports_city_filter_select
. Can you post the procedure definition? This error is characteristic of schemas where the wrong data type has been chosen, and you are storing dates as strings. This will continue to cause problems until it is corrected at source. i.e. store dates as dates. – GarethD