Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

DELPHI - DATEDIFF FROM STRING

Posted on 2010-11-30
6
Medium Priority
?
1,257 Views
Last Modified: 2013-11-23
hi,
I used the function that is fine, now I need to use it with a date format string.

now i need...

var y,m,d,h,n,s,ms: Word;
begin
  DATAINIZIO:= Now;
  DATAFINE:= // it's in string format, for example 2011/09/24 ;
  DiffDates(DATAINIZIO, DATAFINE, y,m,d,h,n,s,ms);
end;
0
Comment
Question by:danz67
[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
  • 4
  • 2
6 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 34237377
this depends on how you receive the string

is it from user input ? > here the language settings are of importance
is it from database > the definition probably never changes

DataFine := StrToDate(YourDateInString);

you could write your own conversion routine:


function ConvertToDate(S: String): TDateTime;
var Fmt: TFormatSettings;
begin
  GetLocaleFormatSettings(LOCALE_USER_DEFAULT, fmt);
  try
    fmt.ShortDateFormat := 'DD/MM/YYYY';
    Result := StrToDate(S, Fmt);
  except
    raise Exception.CreateFmt('String could not be converted to a date with short date format = "%s"', [fmt.ShortDateFormat]);
  end;
end;

Open in new window

0
 

Author Comment

by:danz67
ID: 34237427
I have try this, but not work.

var
  DATAINIZIO: Tdate;
  DATAFINE: TDate;
begin
  DATAINIZIO:= Now;
  DATAFINE:= ConvertToDate(Edit1.Text); // it's in string format, for example 2011/09/24 ;
  DiffDates(DATAINIZIO, DATAFINE, y,m,d,h,n,s,ms);
end;
0
 

Author Comment

by:danz67
ID: 34237431
provided the date is so, not language-dependent system
AscoltaTrascrizione fonetica
Dizionario - Visualizza dizionario dettagliatosostantivo0.laabbreviazione0.Apronome0.it0.her0.youarticolo0.the0.a0.an
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 200 total points
ID: 34237433
well your format is the following :

function ConvertToDate(S: String): TDateTime;
var Fmt: TFormatSettings;
begin
  GetLocaleFormatSettings(LOCALE_USER_DEFAULT, fmt);
  try
    fmt.ShortDateFormat := 'YYYY/MM/DD';
    Result := StrToDate(S, Fmt);
  except
    raise Exception.CreateFmt('String could not be converted to a date with short date format = "%s"', [fmt.ShortDateFormat]);
  end;
end;

Open in new window

0
 

Author Comment

by:danz67
ID: 34237435
sorry..google translate :(

 provided the date is so, not language-dependent system
0
 

Author Closing Comment

by:danz67
ID: 34237453
great
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
Suggested Courses

609 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