Dates :-/

Posted on 2005-03-27
Medium Priority
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...

Question by:DavidBirch2dotCom
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
LVL 13

Accepted Solution

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;
  Months:array[1..12] of string=('Jan', 'Feb', 'March', 'April', 'May', 'June', 'July', 'Aug', 'Sept', 'Oct', 'Nov', 'Dec');
  X, MM, DD, YY:Word;
  //*** 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
  //*** 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
  Result:=EncodeDate(YY, MM, DD)

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

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

best regards

Author Comment

ID: 13639692
Thanks for the help :)

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