Solved

Comparing Dates

Posted on 2007-11-28
25
412 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
[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
  • 15
  • 9
25 Comments
 
LVL 19

Expert Comment

by:MerijnB
ID: 20365140
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
ID: 20365192
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
ID: 20365318
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
Industry Leaders: 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!

 

Author Comment

by:ST3VO
ID: 20365358
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
ID: 20365360
Now working but not looping.... :o/
0
 

Author Comment

by:ST3VO
ID: 20365412
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
ID: 20365496
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
ID: 20384315
Anyone please???
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20384329
if you debug this, what happens if you hit a 404?
0
 

Author Comment

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

0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20384562
please read my question:

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

Author Comment

by:ST3VO
ID: 20384592
Sorry but how do I do that at runtime? :o(

0
 
LVL 19

Expert Comment

by:MerijnB
ID: 20384611
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
ID: 20384674
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
ID: 20384785
what happens if you remove the continue from the except?
0
 

Author Comment

by:ST3VO
ID: 20384792
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
ID: 20384803
Still hungs!!!

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

Expert Comment

by:MerijnB
ID: 20384812
does it hang, or does it stop looping?
0
 

Author Comment

by:ST3VO
ID: 20384821
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
ID: 20384847
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
ID: 20384855
oops, forgot the remove the continue; from the except part, take that out please


try
 ...
except
end;
0
 

Author Comment

by:ST3VO
ID: 20384878
Still hungs!

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

Expert Comment

by:MerijnB
ID: 20384900
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
ID: 20384905
No probs!!!

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

Author Closing Comment

by:ST3VO
ID: 31411395
Thanks....I've opened another more specific question!
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

691 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