Solved

Comparing Dates

Posted on 2007-11-28
25
395 Views
Last Modified: 2010-04-21
Hi all,

I am getting the Last Modified Stamp on images online using Idhttp1.Head command.

Like this:

Idhttp1.Head('http://imageserver.autoexposure.co.uk/autoedit/AETA10120/AETV15462190_1b.jpg');
Edit1.Text:=(Idhttp1.Response.RawHeaders.Values['Last-Modified']);

This is returning:
Wed, 29 Aug 2007 11:49:57 GMT

Then I have today's datetime in the same format:
Code: s:=FormatDateTime('ddd, d mmm yyyy hh:mm:ss "GMT"', now);

Which returns:
Wed, 28 Nov 2007 12:01:02 GMT

Up to there all ok!

What I need to know is if the image was modified Today or now.

So, if the image LastModified Stamp is older than today do something....

If the image LastModified Stamp was modified today then do something else...

I don't know if this is right but as I don't want to compare the time etc...Just the dates I have Trimed
the data so it just leaves to date.

Like this:

DataTimeNow:=AnsiLeftStr(DateTimeNow, 16);
ImageStampDate:=AnsiLeftStr(ImageStampDate, 16);

This leave me with: Wed, 28 Nov 2007

Now....

How do I compare the date so I know if the image was modified today or not???

Hope you can help

Thanks

ST3VO
0
Comment
Question by:ST3VO
  • 15
  • 9
25 Comments
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
if you only want to check if it wasn't today simply see if the strings match:
 ...
 

 DataTimeNow:=AnsiLeftStr(DateTimeNow, 16);

 ImageStampDate:=AnsiLeftStr(ImageStampDate, 16);
 

 if DateTimeNow = ImageStampDate then

 begin

  // it was today!

 end;

Open in new window

0
 
LVL 13

Expert Comment

by:rfwoolf
Comment Utility
Okay when comparing dates you must get them into date format (can't leave them as strings), so for this you can use StrToDate function:
  function StrToDate(const S: string; var FormatSettings: TFormatSettings): TDateTime; overload;
You can look this up in the delphi help file, but here is an example that might work:

StrToDate(MyString, FormatSettings);

(You just need to look up TFormatSettings to get this right)

Then to compare two dates you can add DateUtils to your unit and use this:
function CompareDate(const A: TDateTime; const B: TDateTime): TValueRelationship;
example:
If CompareDate(DateOne, DateTwo) = 1 then //Then DateOne > DateTwo
...
If CompareDate(DateOne, DateTwo) = -1 then //Then DateOne < DateTwo
0
 

Author Comment

by:ST3VO
Comment Utility
I'm trying this but get "unknown protocol" error:

Any Ideas???
procedure TForm1.Button3Click(Sender: TObject);
 

var ImageStampDate, DataTimeNow : String;

i: integer;

begin

for i := 0 to ListBox1.Items.Count - 1 do //Loop the listbox items

    begin

      Idhttp1.Head(IntToStr(i)); //Assign the current selection count

      ImageStampDate:=(Idhttp1.Response.RawHeaders.Values['Last-Modified']); //Get Last Modified from image online

      DataTimeNow:=FormatDateTime('ddd, d mmm yyyy hh:mm:ss "GMT"', now); //Get Now FormatDate

      ImageStampDate:=AnsiLeftStr(ImageStampDate, 16); //Only leave the Date

      DataTimeNow:=AnsiLeftStr(DataTimeNow, 16);  //Only leave the Date

      if DataTimeNow <> ImageStampDate then listbox1.Items.Delete(i); // Clear it not new
 

    end;

end;

Open in new window

0
 

Author Comment

by:ST3VO
Comment Utility
Opps...my mistake:

It's  Idhttp1.Head(Listbox1.Items[i]); //Assign the current selection count

not

Idhttp1.Head(IntToStr(i)); :o/  hehehe :o)
0
 

Author Comment

by:ST3VO
Comment Utility
Now working but not looping.... :o/
0
 

Author Comment

by:ST3VO
Comment Utility
Update:

This is now working...although I need to test the results....

procedure TForm1.Button3Click(Sender: TObject);
 

var ImageStampDate, DataTimeNow : String;

i: integer;

begin

for i := 0 to ListBox1.Items.Count - 1 do //Loop the listbox items

    begin

      //if i > 0 then

       Begin

      Idhttp1.Head(Listbox1.Items[i]); //Assign the current selection count

      ImageStampDate:=(Idhttp1.Response.RawHeaders.Values['Last-Modified']); //Get Last Modified from image online

      DataTimeNow:=FormatDateTime('ddd, d mmm yyyy hh:mm:ss "GMT"', now); //Get Now FormatDate

      ImageStampDate:=AnsiLeftStr(ImageStampDate, 16); //Only leave the Date

      DataTimeNow:=AnsiLeftStr(DataTimeNow, 16);  //Only leave the Date

      if DataTimeNow <> ImageStampDate then

        begin

        listbox1.Items.Delete(i); // Clear it not new

        Edit1.Text:=IntToStr(i);

        end;

        Application.ProcessMessages;

       end;

    end;

end;

Open in new window

0
 

Author Comment

by:ST3VO
Comment Utility
OK.....The loops stops if the url is not found...404 message.

I'm trying

Try

Except

But it's not continuing...

Any ideas?

Here is the code:


procedure TForm1.Button3Click(Sender: TObject);
 

var ImageStampDate, DataTimeNow : String;

i: integer;

begin
 

  for i := 0 to ListBox1.Items.Count - 1 do //Loop the listbox items

    begin

      //if i > 0 then

      // Begin
 

    try

      Idhttp1.Head(Listbox1.Items[i]); //Assign the current selection count

      ImageStampDate:=(Idhttp1.Response.RawHeaders.Values['Last-Modified']); //Get Last Modified from image online

      DataTimeNow:=FormatDateTime('ddd, d mmm yyyy hh:mm:ss "GMT"', now); //Get Now FormatDate

      ImageStampDate:=AnsiLeftStr(ImageStampDate, 16); //Only leave the Date

      DataTimeNow:=AnsiLeftStr(DataTimeNow, 16);  //Only leave the Date

      if DataTimeNow <> ImageStampDate then

        begin

        listbox1.Items.Delete(i); // Clear it not new

        Edit1.Text:=IntToStr(i);

       end;

      Application.ProcessMessages;

    Except

      continue;

    end;
 

end;

end;

Open in new window

0
 

Author Comment

by:ST3VO
Comment Utility
Anyone please???
0
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
if you debug this, what happens if you hit a 404?
0
 

Author Comment

by:ST3VO
Comment Utility
Yes, I just need to ignore the 404 message and continue the loop!

0
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
please read my question:

If you debug this code, what happens if you encounter a 404?
0
 

Author Comment

by:ST3VO
Comment Utility
Sorry but how do I do that at runtime? :o(

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
place a breakpoint in the code (set your cursor on line 7) and press F5. A red dot will appear in front of the line.

Now run the code, it will stop at the place you've put the breakpoint.

Now by pressing F8, you 'walk' through the lines one by one. See what happens if you come across the 404.
0
 

Author Comment

by:ST3VO
Comment Utility
It says No Debug Info...

But after a long while I get a 404 exception message

Debugger Exception Notification

Project Project1.exe raised exception class EidHttpProtocolException with message 'HTTP/1.1 404 Not Found'.


Breaks on this line:

Idhttp1.Head(Listbox1.Items[i]); //Assign the current selection count
ImageStampDate:=(Idhttp1.Response.RawHeaders.Values['Last-Modified']); <---HERE

But it could be the one above!

Hope this helps!
0
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
what happens if you remove the continue from the except?
0
 

Author Comment

by:ST3VO
Comment Utility
I just want to skip that error so the loop continues if the error occures. That's all I need!


I've even tryed:

Try

Except
  break;

But it still hangs :o(
0
 

Author Comment

by:ST3VO
Comment Utility
Still hungs!!!

It's like it's ignoring the except part :o/
0
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
does it hang, or does it stop looping?
0
 

Author Comment

by:ST3VO
Comment Utility
I've taken the try ...except off...as it;s doing nothing...

This is my current code:


procedure TForm1.Button3Click(Sender: TObject);
 

var ImageStampDate, DataTimeNow : String;

i: integer;

begin
 

  for i := 0 to ListBox1.Items.Count - 1 do //Loop the listbox items
 

    begin

      if i > 0 then

       Begin
 

 

      Idhttp1.Head(Listbox1.Items[i]); //Assign the current selection count

      ImageStampDate:=(Idhttp1.Response.RawHeaders.Values['Last-Modified']); //Get Last Modified from image online
 

      DataTimeNow:=FormatDateTime('ddd, d mmm yyyy hh:mm:ss "GMT"', now); //Get Now FormatDate

      ImageStampDate:=AnsiLeftStr(ImageStampDate, 16); //Only leave the Date

      DataTimeNow:=AnsiLeftStr(DataTimeNow, 16);  //Only leave the Date

      if DataTimeNow <> ImageStampDate then

        begin

        listbox1.Items.Delete(i); // Clear it not new

        Edit1.Text:=IntToStr(i);

       end

      end;

      Application.ProcessMessages;
 

    end;

end;

Open in new window

0
 
LVL 19

Accepted Solution

by:
MerijnB earned 500 total points
Comment Utility
put in the try except, but don't put anything in the except part
procedure TForm1.Button3Click(Sender: TObject);

 

var ImageStampDate, DataTimeNow : String;

i: integer;

begin

 

  for i := 0 to ListBox1.Items.Count - 1 do //Loop the listbox items

    begin

      //if i > 0 then

      // Begin

 

    try

      Idhttp1.Head(Listbox1.Items[i]); //Assign the current selection count

      ImageStampDate:=(Idhttp1.Response.RawHeaders.Values['Last-Modified']); //Get Last Modified from image online

      DataTimeNow:=FormatDateTime('ddd, d mmm yyyy hh:mm:ss "GMT"', now); //Get Now FormatDate

      ImageStampDate:=AnsiLeftStr(ImageStampDate, 16); //Only leave the Date

      DataTimeNow:=AnsiLeftStr(DataTimeNow, 16);  //Only leave the Date

      if DataTimeNow <> ImageStampDate then

        begin

        listbox1.Items.Delete(i); // Clear it not new

        Edit1.Text:=IntToStr(i);

       end;

      Application.ProcessMessages;

    Except

      continue;

    end;

 

end;

end;

Open in new window

0
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
oops, forgot the remove the continue; from the except part, take that out please


try
 ...
except
end;
0
 

Author Comment

by:ST3VO
Comment Utility
Still hungs!

Used to hung url 40 ....now it hungs on 97....but same error :o/
0
 
LVL 19

Expert Comment

by:MerijnB
Comment Utility
I could try to reproduce it here, but I'll need the list of img urls (or at least one that goes wrong).
Unfortunately, I don't have time for that now, maybe monday :|
0
 

Author Comment

by:ST3VO
Comment Utility
No probs!!!

Thanks!!! I'll keep on trying :o)
0
 

Author Closing Comment

by:ST3VO
Comment Utility
Thanks....I've opened another more specific question!
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

18 Experts available now in Live!

Get 1:1 Help Now