chrispaton
asked on
Date as Input Parameter
Hi,
I am struggling to filter a asp.net c# query with a unix date input parameter, I am trying to filter my query results between todays date and a date 14 days later. I think I am getting mixed up with the format of the date to input into the string as I have tried a lot of diferent options but get format string error messages back when I run the page. Here is my code I have so far, ;
DateTime DateParameter = DateTime.Today;
DateTime DateParameter1 = DateTime.Today.AddDays(14) ;
double Parameter = Util.ConvertToUnixTimestam p(DatePara meter);
double Parameter1 = Util.ConvertToUnixTimestam p(DatePara meter1);
e.InputParameters["Date"] = Parameter.ToString();
e.InputParameters["Date1"] = Parameter1.ToString();
I have replaced
e.InputParameters["Date"] = Parameter.ToString();
e.InputParameters["Date1"] = Parameter1.ToString();
with
e.InputParameters["Date"] = "1018310400";
e.InputParameters["Date1"] = "101952000";
which works perfectly, but when I run the first bit of code no results are displayed.
Thanks
Chris
I am struggling to filter a asp.net c# query with a unix date input parameter, I am trying to filter my query results between todays date and a date 14 days later. I think I am getting mixed up with the format of the date to input into the string as I have tried a lot of diferent options but get format string error messages back when I run the page. Here is my code I have so far, ;
DateTime DateParameter = DateTime.Today;
DateTime DateParameter1 = DateTime.Today.AddDays(14)
double Parameter = Util.ConvertToUnixTimestam
double Parameter1 = Util.ConvertToUnixTimestam
e.InputParameters["Date"] = Parameter.ToString();
e.InputParameters["Date1"]
I have replaced
e.InputParameters["Date"] = Parameter.ToString();
e.InputParameters["Date1"]
with
e.InputParameters["Date"] = "1018310400";
e.InputParameters["Date1"]
which works perfectly, but when I run the first bit of code no results are displayed.
Thanks
Chris
ASKER
This is the select parameter details;
<SelectParameters>
<asp:Parameter Name="Date" Type="String" />
</SelectParameters>
<SelectParameters>
<asp:Parameter Name="Date1" Type="String" />
</SelectParameters>
The values hard coded are supposed to be what the parameter and parameter1 should be returning but are not, I added the hard coded values to make sure that I was parsing something to the page and that my query was correct.
<SelectParameters>
<asp:Parameter Name="Date" Type="String" />
</SelectParameters>
<SelectParameters>
<asp:Parameter Name="Date1" Type="String" />
</SelectParameters>
The values hard coded are supposed to be what the parameter and parameter1 should be returning but are not, I added the hard coded values to make sure that I was parsing something to the page and that my query was correct.
>>The values hard coded are supposed to be what the parameter and parameter1 should be returning but are not.
So Util.ConvertToUnixTimestam p is not performing properly.
Can you post its code?
So Util.ConvertToUnixTimestam
Can you post its code?
ASKER
public class Util
{
/// <summary>
/// Convert a date time to unix timestamp
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static double ConvertToUnixTimestamp(Dat eTime date)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan diff = date - origin;
return Math.Floor(diff.TotalSecon ds);
}
/// <summary>
/// Convert a unix timestamp to a date time
/// </summary>
/// <param name="timestamp"></param>
/// <returns></returns>
public static DateTime ConvertFromUnixTimestamp(d ouble timestamp)
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestam p);
}
}
{
/// <summary>
/// Convert a date time to unix timestamp
/// </summary>
/// <param name="date"></param>
/// <returns></returns>
public static double ConvertToUnixTimestamp(Dat
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
TimeSpan diff = date - origin;
return Math.Floor(diff.TotalSecon
}
/// <summary>
/// Convert a unix timestamp to a date time
/// </summary>
/// <param name="timestamp"></param>
/// <returns></returns>
public static DateTime ConvertFromUnixTimestamp(d
{
DateTime origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestam
}
}
What happens if you change the math.floor call to an explicit (long) cast? And return a long?
http://andrewgunn.blogspot.com/2008/07/how-do-i-convert-unix-timestamp-into.html
http://andrewgunn.blogspot.com/2008/07/how-do-i-convert-unix-timestamp-into.html
ASKER
I have changed the math.floor call to (long) and return a long as you suggested but it's still not returning anything.
Please help
Please help
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi daniel,
thanks for your help.this was the code we used without the doubles and it works.
e.InputParameters["Date"] = Util.ConvertToUnixTimestam p(DateTime .Today).To String();
e.InputParameters["Date1"] = Util.ConvertToUnixTimestam p(DateTime .Today.Add Days(21)). ToString() ;
much appreciated
chris
thanks for your help.this was the code we used without the doubles and it works.
e.InputParameters["Date"] = Util.ConvertToUnixTimestam
e.InputParameters["Date1"]
much appreciated
chris
ASKER
hi daniel.
thanks for your help.
this was the code without the doubles and it works
e.InputParameters["Date"] = Util.ConvertToUnixTimestam p(DateTime .Today).To String();
e.InputParameters["Date1"] = Util.ConvertToUnixTimestam p(DateTime .Today.Add Days(21)). ToString() ;
much appreciated
chris
thanks for your help.
this was the code without the doubles and it works
e.InputParameters["Date"] = Util.ConvertToUnixTimestam
e.InputParameters["Date1"]
much appreciated
chris
Those values you hard-coded to test -- are they EXACTLY what Parameter.ToString() and parameter1.ToString() are returning?