| Author |
Topic Search Topic Options
|
Maxi
Groupie
Joined: 24 October 2002
Location: United Kingdom
Status: Offline
Points: 49
|
Post Options
Thanks(0)
Quote Reply
Topic: Months between two dates Posted: 04 February 2004 at 11:15am |
Hi there,
I am busy making a little events calendar for my website where I allow users to submit events. At the moment I have the months of the year set as categories, so if the event occurs in January the user will choose the January category: However I can see that this is hardly effective when an event occurs for example over 4 months (eg. 01/01/04 - 01/04/04), as if they press the category February the event will not show up because it is in The january Category.
MY question is then, how can I get the month numbers between two Dates so that I can use them in a statement (eg. Jan-April has month numbers 1,2,3,4). to call all Events for a particular month.
Hope somebody can help out here.
Kind Regards
Maxi
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
Posted: 04 February 2004 at 12:14pm |
Well, the best thing is to have 2 fields in the db: StartingDate & EndingDate and the use appropriate select queries to trigger the right result.
According to your needs you should use an appropriate Date Function (dateAdd or datePart). More about asp functions here.
Sorry I have putted a wrong url in the first place.
Edited by zaboss
|
|
|
 |
Maxi
Groupie
Joined: 24 October 2002
Location: United Kingdom
Status: Offline
Points: 49
|
Post Options
Thanks(0)
Quote Reply
Posted: 04 February 2004 at 2:08pm |
Hi zaboss,
Thanks for your quick reply.
I already have two date fields in my database (start and end date).
What I am wanting to do is Ad a function on the Form, where the user submits the Event, that will give me the months between two Dates.
Then I would like to Take the result of this calculation and have it on the Form as a Hidden Field which gets posted to a new field in my database.
Once I have these fields in my Database it will be easy to make the selection for months( Example WHERE months=1)
I am not a star programer and was hoping that somebody could tell me if what I want done above can be done, and where to find the proper means of adding this function to my page.
Thanks for the microsoft VB link, but being an amateur I was hoping for some kind of Tutorial or link that explains to a "Dummy Like Me" how to go about making this feature;)
Kind Regards and thanks again
Maxi
|
 |
Maxi
Groupie
Joined: 24 October 2002
Location: United Kingdom
Status: Offline
Points: 49
|
Post Options
Thanks(0)
Quote Reply
Posted: 04 February 2004 at 3:20pm |
Question refraced,
Sorry to write so soon again but I would like to refrace the question that I have asked, as it might make what I am trying to do more clear.
The first question is: Is it at all possible to get the name of the months between two dates? The reason that I ask is because every article I am reading about Datediff seems to only be able to produce the number of months between two dates and not the month names (Or month numbers).
The second question is: If it is possible would I be able to add the month (Multiple months) name to one field in the database, from which I could direct my queries at?
Kind regards, and I hope that my need are clearer now;)
Maxi
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
Posted: 05 February 2004 at 4:02am |
|
Basically, what you want is that if an event starts 12 january and ends 14 april to enter in the db january, february, march, april? Isn't it?
|
|
|
 |
Maxi
Groupie
Joined: 24 October 2002
Location: United Kingdom
Status: Offline
Points: 49
|
Post Options
Thanks(0)
Quote Reply
Posted: 05 February 2004 at 5:22am |
Hi Zaboss,
Thanks for replying,
Yes that is exactly what I would like to do. It would however be best if those months could be written as there VBSCRIPT month number (As it would be easy to call the month by its number).
Do you have any suggestions on how to do this, bare in mind that I am still an amateur;)
Kind Regards Maxi
|
 |
zaboss
Senior Member
Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
|
Post Options
Thanks(0)
Quote Reply
Posted: 05 February 2004 at 5:42am |
Not sure if this is the best way of doing this, but here it is what I'll do (at least, until I find a better way ).
StrLast = DateDiff("m", Request.Form("EndDate"), Request.Form("StartDate")) StrStart =DatePart("m", Request.Form("StartDate") StrEnd = DatePart("m", Request.Form("EndDate")
For i = StrStart to StrEnd Insert Into... ' insert into the db the values you get If i > StrEnd then Exit for next
|
Something like that...
|
|
|
 |
Maxi
Groupie
Joined: 24 October 2002
Location: United Kingdom
Status: Offline
Points: 49
|
Post Options
Thanks(0)
Quote Reply
Posted: 05 February 2004 at 7:40am |
Hi zaboss
Is it possible for you to make the above demo with dates so that I can run it on a test page and see the results? How van I call the results to be displayed on my page?
I have added dates like this below, and now I would like to see the results before I start trying to figure out how to put the results into a hidden field on my form;)
<% StrLast = DateDiff("m", 15-10-2003, 15-07-2003) StrStart =DatePart("m", 15-07-2003) StrEnd = DatePart("m", 15-10-2003)
For i = StrStart to StrEnd If i > StrEnd then Exit for next %>
Thanks in advance
Regards
Maxi
|
 |