Web Analytics Made Easy -
StatCounter Showing records after a specific time - CodingForum

Announcement

Collapse
No announcement yet.

Showing records after a specific time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Showing records after a specific time

    Hi guys

    I hope this is one that you can help me with.

    Bascially I have the following table:

    Eventtitle | Eventdate | Starttime
    New Balance Trainer Release | 2016-03-26 | 15:00:00
    Nike Trainer Release | 2016-08-26 | 15:00:00
    Puma Trainer Release | 2016-10-11 | 09:56:00

    The "eventdate" datatype is "Date" in MS SQL Server
    The "starttime" datatype is "time(0)" in MS SQL Server

    I'm currently querystring my table so that I can display the single event that is either on today or closest to today's date (a date in the future). To do this is use:


    select top 1 eventid, eventdate, starttime
    from mytable
    where eventdate >= CONVERT(date,GETDATE())
    order by eventdate


    This works perfectly and using the above exmaple my page would display "Nike Trainer release" as the "New balance" event is in the past. However, I have a problem if there are two events on the same day like so:

    Eventtitle | Eventdate | Starttime
    New Balance Trainer Release | 2016-03-26 | 15:00:00
    Nike Trainer Release | 2016-08-26 | 15:00:00
    Asics Trainer Release | 2016-08-26 | 12:00:00
    Puma Trainer Release | 2016-10-11 | 09:56:00

    My script will rightly display the "Asics Trainer Release" record as it's earlier in the day however..........

    and here's my problem.....

    what if I only want to display events that are at the current time or at a time in the future? So, if today is the 26th Aug 2016 and the current time happens to be 2pm then how would I get my statement display the "Nike Trainer Release" record?

    It's like I needs something like


    where eventdate >= CONVERT(date,GETDATE()) AND where starttime >= CONVERT(time,GETTIME())


    but this is just made up and won't work. I have been on this for 4 day and still can't find the solution.

    If anyone can help then I would be fully appreciated

    Best regards

    Rod from the UK

  • #2
    Assuming that the date and time ate correctly stored in a datetime field you can simply test for that value being > NOW()
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

    Comment

    Working...
    X