Solved

4-digit date

Posted on 1997-11-25
5
137 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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