• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

Dates :-/

This is irritating me...

I have a database running with a dbEdit holding a date feild, I want to write to it...

I have:
Month - in a string varible eg 'March'
Day - in a string varible eg '27'
I guess you can get the year from the now function (?)

How do I put them together in a format the database will accept (its a dbase database)

could someone please save me half an hours fiddling and write a function to do this...

Thanks
0
DavidBirch2dotCom
Asked:
DavidBirch2dotCom
1 Solution
 
BlackTigerXCommented:
you need to put that in a standard date format, then convert it to a date type, something like:

function MyDateToDate(const Month, Day:string):TDateTime;
const
  Months:array[1..12] of string=('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
var
  X, MM, DD, YY:Word;
begin
  MM:=0;
  //*** First, get the year
  DecodeDate(Now, YY, MM, DD);
  //*** then get the month, there are other methods you can use to improve speed, like using a sorted TStringList
  for X:=1 to 12 do
    if (UpperCase(Month)=UpperCase(Months[X])) then
    begin
      MM:=X;
      Break
    end;
  //*** here you can default the month, or whatever  you want to do if the month is invalid
  if (MM=0) then
    raise Exception.Create('Invalid month: ['+Month+']');
  //*** here you can use StrToIntDef in case the day string is invalid
  DD:=StrToInt(Day);
  Result:=EncodeDate(YY, MM, DD)
end;

then you just call this function to assign it to your Date field

YourField.AsDateTime:=MyDateToDate('March', '27')

best regards
0
 
DavidBirch2dotComAuthor Commented:
Thanks for the help :)
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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now