question

ratzy avatar image
ratzy asked

ASP.NET Displaying data between dates

hi there, I am wanting to show data in textbox1 between the selected date and 3 months prior to that date. So far I have this. startMonth is the month and year which was selecet by the user... TextBox1.Text = TextBox1.Text + "EFFECTIVE_TRANSACTION_DATE" + " " + "BETWEEN" + " " + "'" + startMonth((-3) + "'" + " " + "AND" + " " + "'" + startMonth + "'" + " "; I want it to basically be TextBox1 displays what ever is in the text box then EFFECTIVE_TRANSACTION_DATE Between (3 months back) AND (month selected) Thanks
asp.net
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Magnus Ahlkvist avatar image
Magnus Ahlkvist answered
How does startMonth look? Is it a string value? What form is it on? You say it is the month and year. Are they an integer - like 201109 or are they a string on some form? If you have a string with year and month, on the form 201109 you could do: TextBox1.Text += "EFFECTIVE_TRANSACTION_DATE BETWEEN DATEADD(m,-3,'" + _ startMonth + "01 00:00:00.000') AND '" + startMonth + "01 00:00:00.000'" Otherwise, if this is stored some other way, please share some more information about what you have.
5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ratzy avatar image ratzy commented ·
Hi there, Thanks for your fast response. startMonth is a string that looks like - 'march-2011'
0 Likes 0 ·
Magnus Ahlkvist avatar image Magnus Ahlkvist commented ·
Ok, then I'd go for deconstructing it, and get it to the form 201103 instead. I guess that could be done by first using SPLIT to get the two parts to an array, and then using a switch-statement in C# to get it to that form. Something like this: String() arr=startMonth.Split('-'); String s; switch(arr(0).ucase()) { case "JANUARY": s="01"; break; case "FEBRUARY": s="02"; break; .. .. case "DECEMBER": s="12"; break; } String sDate sDate=arr(1) + s + "01 00:00:00.000" TextBox1 += EFFECTIVE_TRANSACTION_DATE BETWEEN DATEADD(m,-3,'" + sDate + "') AND '" + sDate + "'" I'm not good at C#, so the syntax probably won't work at all, so see it as pseudocode and C#-fy it yourself.
0 Likes 0 ·
ratzy avatar image ratzy commented ·
Thanks Very much, when i do this it says i cant use Split... I have this so far if ( ddMonthControl.ID == "startMonth" && dateOptions.SelectedIndex == 1) { String date = startMonth.ID; char[] separator = new char[] { '-' }; string[] strSplitArr = date.Split(separator); string s; switch (date) { case "JANUARY": s = "01"; break; case "FEBRUARY": s = "02"; break; ... case "DECEMBER": s = "12"; break; } String sDate; sDate = date + s + "01 00:00:00.000"; TextBox1.Text = TextBox1.Text + "EFFECTIVE_TRANSACTION_DATE BETWEEN DATEADD(m,-3,''" + sDate + " '') AND '" + sDate + "'"; } The error I get is the bottom s in sDate = date + s it says use of a unassigned local variable...
0 Likes 0 ·
Magnus Ahlkvist avatar image Magnus Ahlkvist commented ·
Your switch doesn't get a hit. That's probably because you switch on the whole data-string. You should switch on the Month-part of the date, and you should also convert it to uppercase, because string comparison is case sensitive.
0 Likes 0 ·
ratzy avatar image ratzy commented ·
Thanks for your help :)
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.