?
Solved

Dates :-/

Posted on 2005-03-27
2
Medium Priority
?
189 Views
Last Modified: 2010-04-05
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
Comment
Question by:DavidBirch2dotCom
[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
2 Comments
 
LVL 13

Accepted Solution

by:
BlackTigerX earned 500 total points
ID: 13639450
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
 
LVL 7

Author Comment

by:DavidBirch2dotCom
ID: 13639692
Thanks for the help :)
0

Featured Post

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!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 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