Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

I need to compare dates (2)

Posted on 2007-11-30
17
Medium Priority
?
714 Views
Last Modified: 2010-04-21
Hi all,

I need an example code please:

I've got 2 dates in this format: Fri, 30 Nov 2007

I need to compare:

Fri, 30 Nov 2007 with Wed, 29 Aug 2007 for example...

And be able to compare if a date is older than today of 2 days ago.

I'll give full points for an example code please!

Hope you can help...

Thanks

ST3VO
0
Comment
Question by:ST3VO
[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
  • 4
  • 2
  • +3
17 Comments
 
LVL 18

Expert Comment

by:Johnjces
ID: 20385511
I do not understand;

"...than today of 2 days ago?"

Can you explain what this means?

Do you want to subtract two days from 'today' and compare that with the one or both of the dates?

Thx.

John
0
 

Author Comment

by:ST3VO
ID: 20385539
Right....

Everyday, I need to compare a list of images (last Modified) with another...so I only keep the need ones.

Last modified today on weekday!

So, on instance 1 Monday to Friday ....I run the program everyday to check if there are any images modified that day!

When it comes to the weekend t's different because I need to get all images 2 day's old or newer!

Hope this explains it better!

Thanks

ST3VO
0
 
LVL 18

Expert Comment

by:Johnjces
ID: 20385610
Someone will probably get you the answer and full code you desire, but in any case, here is a start. (Don't have Delphi right now to test or do much).

Use EncodeDate in SysUtils

Parse your text dates into its parts, turn the day, into the numeric day i.e., WED = 4, and do:

if EncodeDate(YearNow, MonthNow, DayNow) - 2 > EncodeDate(YearLastFri, MonthLastFri, DayLastFri) then
 ShowMessage('Today is greater than Last Friday by two days');

We would subtract 2  from the current date to adjust for the weekend or 2 days before today.

Might get ya going until I or someone else codes it all up for you.

Hope I helped a bit.

John
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 3

Expert Comment

by:pablo_munoz
ID: 20385687
I think I understand, but maybe you could clarify. You have 2 dates 11/01/2007 - 10/01/2007 , which one of these dated do you want to check against DateTime.Today.AddDays(-2)
0
 
LVL 1

Expert Comment

by:tammoz
ID: 20386251
hi
have a look on these tow functions and then decide what you want to do:
1.
function CompareDate(const ADate, BDate: TDateTime) : TValueRelationship

Compares two TDateTime values (returns "less", "equal" or "greater"). Ignores the Time part if both values "fall" on the same day.

TValueRelationship represents the relationship between two values. Each of three TValueRelationship values has a "liked" symbolic constant:
-1 [LessThanValue] The first value is less than the second value.
0 [EqualsValue] The two values are equal.
1 [GreaterThanValue] The first value is greater than the second value.

2.
function DayOfTheWeek ( const Date : TDateTime ) : Integer;

The DayOfTheWeek function returns an index number for the day of the week : 1  = Monday
2  = Tuesday
3  = Wednesday
4  = Thursday
5  = Friday
6  = Saturday
7  = Sunday
0
 

Author Comment

by:ST3VO
ID: 20387597
I think I would go for the first one!
0
 

Author Comment

by:ST3VO
ID: 20387671
Can I have some example code please?
0
 
LVL 15

Accepted Solution

by:
mikelittlewood earned 2000 total points
ID: 20387673
Here is a way to convert that particular date format (Fri, 30 Nov 2007) you have back into a TDate property

function TForm1.convertToDate( const pDateString: string): TDate;
var
   dd, mm, yy: word;
   sl: TStringList;
begin
   sl := TStringList.Create;
   try
      sl.DelimitedText := pDateString;

      dd := strToInt( sl.Strings[ 1]);
      mm := monthVal( sl.Strings[ 2]);
      yy := strToInt( sl.Strings[ 3]);

      result := EncodeDate( yy, mm, dd);
   finally
      freeAndNil( sl)
   end;
end;

function TForm1.monthVal( const pMonth: string): smallInt;
var
   i: smallInt;
begin
   result := 0;
   for i := 1 to length( ShortMonthNames) do
      if ShortMonthNames[ i] = pMonth then
      begin
         result := i;
         break;
      end;
end;
0
 

Author Comment

by:ST3VO
ID: 20387685
That's for the conversion but what I really need is to compare dates....

0
 
LVL 1

Expert Comment

by:tammoz
ID: 20389798
I did not yet understand what you really want to do but this may help:

D1 is your date

case DayOfTheWeek(Now) of
    1..5:if D1 = now then
            ShowMessage('Done');
    6,7: if now - D1 <= 2 then
           ShowMessage('Done Weekend');
  else

  end;
0
 
LVL 46

Expert Comment

by:aikimark
ID: 20392000
You can get the file's timestamp directly using the FileAge() function.  You will need to convert this to a system date value with the FiledateToDateTime() function.

Example from:
http://www.delphibasics.co.uk/RTL.asp?Name=FileAge

var
  fileName   : string;
  fileDate   : Integer;

begin
  // Try to open the Unit1.DCU file for the current project
  fileName := 'Unit1.DCU';
  fileDate := FileAge(fileName);

  // Did we get the file age OK?
  if fileDate > -1 then
    ShowMessage(fileName+' last modified date = '+
                DateToStr(FileDateToDateTime(fileDate)));
end;

==================
other examples:
http://www.swissdelphicenter.ch/torry/showcode.php?id=142
http://www.festra.com/eng/snip03.htm
http://www.scalabium.com/faq/dct0046.htm

MP3 example from Borland:
http://codecentral.borland.com/Item/20163
0
 

Author Comment

by:ST3VO
ID: 20392129
The problem is that  the files I need to compare the dates from are online images.

Your example is local!

Would this work online?
0
 
LVL 46

Expert Comment

by:aikimark
ID: 20392149
Are the image files on a LAN file server?  If so, YES.

If not, then what do mean by "online"?
0
 

Author Comment

by:ST3VO
ID: 20392172
They are not on a LAN, They are images on the net!

0
 
LVL 46

Expert Comment

by:aikimark
ID: 20392187
please give us the URL and what method(s) you are using to look at the image files.
0
 

Author Closing Comment

by:ST3VO
ID: 31412034
Done....Thanks to all for your time!
0
 
LVL 46

Expert Comment

by:aikimark
ID: 20392471
Note to international developers:

ShortMonthNames month names depend on the local settings.  Same is true for LongMonthNames array.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

721 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