[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

how to select the greatest date?

Posted on 2001-09-08
7
Medium Priority
?
263 Views
Last Modified: 2012-05-04
I am retrieving a list of dates from the mysql database and from that i want to select the greatest date from them all.. I used sorting method which runs in for loop(by comparision).. But the response time is very slow when the record count reaches more..
help me in finding the solution..
Regards,
Sujatha N.
0
Comment
Question by:sujatharathinam
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 2

Expert Comment

by:ramses
ID: 6466511
Please note that I can change this code to support other types of dates.  Currently, it excepts dates in order of mm/dd/yyyy

If you need to compare dates that are explicitly declared as date (var cTime=new Date()) , please let me know.


<HTML>
<HEAD><TITLE>Date chooser</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function bigger()
{var x1=document.all.xdat1.value;
 var x2=document.all.xdat2.value;
 var x3=biggest(x1,x2);
 document.all.xbig.value=x3}

function biggest(date1, date2)
{
 //compare dates
 //dates must be in format mm/dd/yyyy
 //this can be changed very easaly dough
 var m1=date1.substring(0,2);
 var m2=date2.substring(0,2);
 var d1=date1.substring(3,2);
 var d2=date2.substring(3,2);
 var y1=date1.substring(7);
 var y2=date2.substring(7);
 //now the comparisation can start
 if( y1 > y2) return date1;
 if( y2 > y1) return date2;
 //when years are the same, go to the months
 if( m1 > m2) return date1;
 if( m2 > m1) return date2;
 //years and months are the same, go to the days
 if( d1 > d2) return date1;
 if( d2 > d1) return date2;
 //both dates are the same, so we return -1
 return -1}
//-->
</SCRIPT>
</HEAD>
<BODY>
Date 1 <INPUT TYPE="TEXT" ID="xdat1" SIZE="10" MAXLENGTH="10"><br>
Date 2 <INPUT TYPE="TEXT" ID="xdat2" SIZE="10" MAXLENGTH="10">&nbsp;
<BUTTON ONCLICK="bigger()">Show me</BUTTON><br>
Biggest <INPUT TYPE="TEXT" ID="xbig" SIZE="10" MAXLENGTH="10" READONLY">
</BODY>
</HTML>

Ramses
0
 
LVL 22

Expert Comment

by:CJ_S
ID: 6466653
Use the ORDER BY clause in the sql statement

example:
SELECT * FROM MYTABLE ORDER BY datefieldname DESC

Regards,
CJ
0
 
LVL 2

Expert Comment

by:ramses
ID: 6466657
Is this a JS question or SQL question?


Ramses
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:snakehollywood
ID: 6466750
if the only thing you want is the top date then use

select top1 from table
order by datefield desc
0
 
LVL 1

Accepted Solution

by:
pak_slm earned 200 total points
ID: 6468117
Use select statement as

select max(date) from table;
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6468271
Pak_Sim: Please read the bottom of this page and post comments in questions that already have comments.

Michel
0
 

Author Comment

by:sujatharathinam
ID: 6470602
Thanx for u suggestion.
0

Featured Post

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

650 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