Solved

4-digit date

Posted on 1997-11-25
5
129 Views
Last Modified: 2010-04-04
In trying to comply with Y2K, I have set my BDE configuration to use 4 digit dates.  However, I don't know how to save the date to the date field of a record in a table.  I have used:
      tableDATE.asDateTime := Date;
and it always seems to save it in mm/dd/yy format.  Any guidance on how to save it in mm/dd/yyyy format?
0
Comment
Question by:northstar
5 Comments
 
LVL 5

Expert Comment

by:JimBob091197
ID: 1351813
If you are using Delphi 2 or later it should save the date & time using 4 digits for the year.  It may only display 2 year digits (if your Control Panel is set up this way) but internally all 4 year digits are stored.

JB
0
 
LVL 1

Expert Comment

by:jackb022197
ID: 1351814
Also check your BDE configuration and set the FOURDIGITYEAR parameter to True.
0
 

Author Comment

by:northstar
ID: 1351815
I am using Delphi 1.02 and have set the BDE config to FOURDIGITYEAR.
0
 

Accepted Solution

by:
mshaer earned 50 total points
ID: 1351816
Dates in Delphi are in fact stored as numbers (Julian Dates).
They are recorded as a time difference from a specified date.
This means that regardless of how they are displayed, the
complete date is still being stored.

Try using

DecodeDate(Date, yearw, monthw, dayw);

(where Date is a DateTime and yearw, monthw and dayw are words)

and decodeTime

from the documentation :

type TDateTime = type Double;

Description

Delphi stores date and time values in the TDateTime type. The integral part of a TDateTime value is the number of days that have passed since 12/30/1899. The fractional part of a TDateTime value is the time of day.

Following are some examples of TDateTime values and their corresponding dates and times:
0               12/30/1899 12:00 am
2.75               1/1/1900 6:00 pm
-1.25               12/29/1899 6:00 am
35065               1/1/1996 12:00 am

procedure DecodeDate(Date: TDateTime; var Year, Month, Day: Word);
procedure DecodeTime(Time: TDateTime; var Hour, Min, Sec, MSec: Word);

You can get hold of the entire date, to test this put a button and a label on your form and then in the button event write

var
  yearw, monthw, dayw: word;
begin
  DecodeDate(YourDateHere, yearw, monthw, dayw)
  LabeName.Caption := IntToStr(dayw) + '/' + IntToStr(monthw) + '/' + IntToStr(yearw);
end;

This will display your date as dd/mm/yyyy

for the help details look under TDateTime (type) in the Delphi
Help

good luck
0
 

Author Comment

by:northstar
ID: 1351817
I have solved it myself by setting ShortDateFormat := 'mm/dd/yyyy'
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

758 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now