Solved

Sort by expiry date

Posted on 2008-10-15
11
339 Views
Last Modified: 2013-12-13
I have a table of different competitions. Each as an expiry date in the form:

DD/MM/YYYY

at the moment I am counting the total number of entries using this query:

      $queryTotal = "SELECT COUNT(id) FROM archive_comps;";
      
      $totalResult = mysql_query($queryTotal);
      confirm_query($totalResult);
            
      $total = mysql_fetch_array($totalResult);

However i want to be able to count the entries which are still active ie. have not expired.

How do I do this?

Thanks
0
Comment
Question by:DrZork101
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 17

Expert Comment

by:houssam_ballout
ID: 22718818
you must compare their date with the date of today.

0
 
LVL 6

Expert Comment

by:RemcovC
ID: 22718844
This should do the trick:

$queryTotal = "SELECT COUNT(id) FROM archive_comps WHERE CDate(expirydate)>CURRENT_TIMESTAMP;";
0
 

Author Comment

by:DrZork101
ID: 22718922
when i use that it says:

FUNCTION databaseName1.CDate does not exist

0
 
LVL 6

Assisted Solution

by:RemcovC
RemcovC earned 250 total points
ID: 22718940
oops sorry, it should be cast(expirydate as datetime)
it's sql not vb ^^
0
 
LVL 6

Expert Comment

by:RemcovC
ID: 22718945
(The cast is not needed if the expiredate is already a datetime field)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:DrZork101
ID: 22718980
the expiry date is stored in the database as DD/MM/YYYY

now its says:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') > CURRENT_TIMESTAMP' at line 1

0
 
LVL 1

Expert Comment

by:gtsupport
ID: 22718979
Maybe this will work

$queryTotal = "SELECT COUNT(id) FROM archive_comps WHERE expirydate> now();";<!-- richText -->
0
 

Author Comment

by:DrZork101
ID: 22719007
the query from gtsupport does run, however does no come up with the right results.

does closingDate have to be converted to a specific formatting?
0
 
LVL 6

Expert Comment

by:RemcovC
ID: 22719024
yep to datetime format

you can do that by convert or cast
CAST (closigndate as date)
0
 

Accepted Solution

by:
DrZork101 earned 0 total points
ID: 22719190
Thanks remcovC but that did not work I have solved the problem using:

$queryTotal = "SELECT COUNT(id) FROM archive_comps WHERE STR_TO_DATE(closingDate,'%d/%m/%Y') > CURDATE()";
0
 
LVL 1

Expert Comment

by:gtsupport
ID: 22719364
Great that it answered your problem. I did not think that you would save the expired date field as a string. You might want to change it to a timestamp format for better performance. That way you will not need to call the STR_TO_DATE function.  It will also allow you to  index your  column  to make it faster to retrieve data.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now