|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Dates are Evil! HELP!Unfortunately, the listing is displaying all events, especially those that are even 2 years old. I want to get rid of them and only display events that are today or in the future. I need help! Dim tmpEvents As Events tmpEvents = New EventsMapper().GetEvents() Dim tmpEvent As New [Event] Dim tmpEventListing As String For Each tmpEvent In tmpEvents tmpEventListing += "<font style='font-family: Verdana; font-size: 10px;'>" & tmpEvent.StartDate & "</font>" & " <br> " & "<font style='font-family: Verdana; font-weight: bold; font-size:10px;'>" & "<A href=javascript:openpopup3(" & tmpEvent.ID.ToString & ")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>" If tmpEvent.StartDate <= Date.Now.ToShortDateStringThen Label2.Text = tmpEventListing Else Label2.Enabled = False End If Next This displays all the events, but does nothing for events in the past. Can you help? Wouldn't it be easier to simply change your sql to pull events with
"eventdate >= GETDATE()" <labe***@gmail.com> wrote in message Show quoteHide quote news:1141412106.216107.310820@z34g2000cwc.googlegroups.com... >I have an event listing on my website that is pulling from SQL. > Unfortunately, the listing is displaying all events, especially those > that are even 2 years old. I want to get rid of them and only display > events that are today or in the future. I need help! > > Dim tmpEvents As Events > tmpEvents = New EventsMapper().GetEvents() > Dim tmpEvent As New [Event] > Dim tmpEventListing As String > For Each tmpEvent In tmpEvents > tmpEventListing += "<font style='font-family: Verdana; > font-size: 10px;'>" & tmpEvent.StartDate & "</font>" & " <br> " & > "<font style='font-family: Verdana; font-weight: bold; font-size: > 10px;'>" & "<A href=javascript:openpopup3(" & tmpEvent.ID.ToString & > ")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>" > > If tmpEvent.StartDate <= Date.Now.ToShortDateString > Then > Label2.Text = tmpEventListing > Else > Label2.Enabled = False > End If > Next > > This displays all the events, but does nothing for events in the past. > Can you help? > You'd think so, but no...because the same view is used to display
events on another table in the site that is accessed by users that actually need to see past events to schedule future events. I just figured it would be easy to put a "if the event date is equal to or less than today, display it" addition to my code. Unfortunately now, for some reason it does not seem that easy. Unless I am missing something obvious? Make sure you are actually working on "real" dates. Here you are comparing a
date (or perhaps text ?) with text. For example here in France the 13 of January we'll have : 13/01/2006 < 20/01/1980 as text but of course 20/01/1980 < 13/01/2006 as a date... -- Show quoteHide quotePatrice <labe***@gmail.com> a écrit dans le message de news:1141412106.216107.310820@z34g2000cwc.googlegroups.com... > I have an event listing on my website that is pulling from SQL. > Unfortunately, the listing is displaying all events, especially those > that are even 2 years old. I want to get rid of them and only display > events that are today or in the future. I need help! > > Dim tmpEvents As Events > tmpEvents = New EventsMapper().GetEvents() > Dim tmpEvent As New [Event] > Dim tmpEventListing As String > For Each tmpEvent In tmpEvents > tmpEventListing += "<font style='font-family: Verdana; > font-size: 10px;'>" & tmpEvent.StartDate & "</font>" & " <br> " & > "<font style='font-family: Verdana; font-weight: bold; font-size: > 10px;'>" & "<A href=javascript:openpopup3(" & tmpEvent.ID.ToString & > ")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>" > > If tmpEvent.StartDate <= Date.Now.ToShortDateString > Then > Label2.Text = tmpEventListing > Else > Label2.Enabled = False > End If > Next > > This displays all the events, but does nothing for events in the past. > Can you help? > The dates being posted in the database are being entered as 1/1/1900
and i know Date.Now.ToShortDateString gives a day that says # 3/3/2006 # Are those hash signs messing me up? I just don't understand what's going on. I set a breakpoint and it clearly shows tmpEvent.StartDate as 1/1/2006 and Date.Now as today's date. <labe***@gmail.com> wrote in message
news:1141413115.327630.115170@p10g2000cwp.googlegroups.com... It isn't the hash signs. Apples == Apples. Apples != Oranges. You are > The dates being posted in the database are being entered as 1/1/1900 > and i know Date.Now.ToShortDateString gives a day that says # 3/3/2006# > > Are those hash signs messing me up? I just don't understand what's > going on. I set a breakpoint and it clearly shows tmpEvent.StartDate > as 1/1/2006 and Date.Now as today's date. comparing Apples to Oranges. What you see at a breakpoint is not what is being compared. You should compare a date formatted DB field to Date.Now Are you sure ? IMO the date is not enclosed in # but anyway
ToShortDateString returns a *string*. You shouldn't use this at all to compare "real" dates and not strings : If tmpEvent.StartDate <= Date.Now Then Also keep in mind that the date is not "entered as 1/1/1900" in the database (assuming you have used the appropriate data type). Dates are always stored the same internally. How they are printed depends on regional settings but a given date has always the same internal representation. Just make sure to compare dates to dates (and not dates to strings) so that you compare their intela representation and not how they "look like" as text in a particular language. -- Show quoteHide quotePatrice <labe***@gmail.com> a écrit dans le message de news:1141413115.327630.115170@p10g2000cwp.googlegroups.com... > The dates being posted in the database are being entered as 1/1/1900 > and i know Date.Now.ToShortDateString gives a day that says # 3/3/2006 > # > > Are those hash signs messing me up? I just don't understand what's > going on. I set a breakpoint and it clearly shows tmpEvent.StartDate > as 1/1/2006 and Date.Now as today's date. > <labe***@gmail.com> wrote in message
news:1141412106.216107.310820@z34g2000cwc.googlegroups.com... This looks very wrong. You should compare the internal date representations > If tmpEvent.StartDate <= Date.Now.ToShortDateString as this will prevent problems with different formats etc. <labe***@gmail.com> schrieb
> If tmpEvent.StartDate <= Date.Now.ToShortDateString What's the data type of the StartDate property? If it' isn't String, you > Then should enable Option Strict. Armin Labelle,
As result from the answers from the others, Try this one \\\ If CDate(tmpEvent.StartDate) <= Date.Now 'This converts any right date in your local setting to an internal date, which is in 100 nanoseconds ticsk starting at ISO date 1-1-1 00:00:00 /// I hope this helps, Cor <labe***@gmail.com> schreef in bericht Show quoteHide quote news:1141412106.216107.310820@z34g2000cwc.googlegroups.com... >I have an event listing on my website that is pulling from SQL. > Unfortunately, the listing is displaying all events, especially those > that are even 2 years old. I want to get rid of them and only display > events that are today or in the future. I need help! > > Dim tmpEvents As Events > tmpEvents = New EventsMapper().GetEvents() > Dim tmpEvent As New [Event] > Dim tmpEventListing As String > For Each tmpEvent In tmpEvents > tmpEventListing += "<font style='font-family: Verdana; > font-size: 10px;'>" & tmpEvent.StartDate & "</font>" & " <br> " & > "<font style='font-family: Verdana; font-weight: bold; font-size: > 10px;'>" & "<A href=javascript:openpopup3(" & tmpEvent.ID.ToString & > ")>" & tmpEvent.Title & "</a>" & "</font>" & "<br><br>" > > If tmpEvent.StartDate <= Date.Now.ToShortDateString > Then > Label2.Text = tmpEventListing > Else > Label2.Enabled = False > End If > Next > > This displays all the events, but does nothing for events in the past. > Can you help? >
HttpWebRequest using Certificates
Asynchronous Invoke and the UI thread (using delegates) How to use my default mail client to mail any file? Accessing Mdi Child Form Control form another one What's going on in this ADO2 code Cannot add MSWord reference Countdown/pause/resume timer Testing simple VB code in design time? .NET and MS Word : setting rightAlignment ??? how linkitem and linkTopic to migrate in vb.net |
|||||||||||||||||||||||