Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 447923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:37:06+00:00 2026-05-12T21:37:06+00:00

I know how to use encodedate in Delphi to encode individual YY, MM and

  • 0

I know how to use encodedate in Delphi to encode individual YY, MM and DD into a datetime field or use encodetime to encode individual HH, SS, MM and MS into datetime field but is there a way to specify both date and time into a datetime field?

Coz with encodedate I cannot specify the time and with encodetime I cannot specify the date…

e.g. how can I set a datetime field to 2009-11-28 14:23:12.000

Please help.

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T21:37:06+00:00Added an answer on May 12, 2026 at 9:37 pm

    Try using the EncodeDateTime function declarated in the DateUtils unit.

    function EncodeDateTime(const AYear: Word;
        const AMonth: Word;
        const ADay: Word;
        const AHour: Word;
        const AMinute: Word;
        const ASecond: Word;
        const AMilliSecond: Word): TDateTime;
    

    See this example

    uses
    DateUtils;
    
    var
      myDateTime : TDateTime;
    
    begin
    
     //Your Code
     myDateTime := EncodeDateTime(2009, 11, 28, 14, 23, 12, 000);
     //Your Code
    
    
    End;
    

    Another option

    uses
    SysUtils;
    
    var
    myDateTime : TDateTime;
    begin
     //Your Code
     myDateTime:= EncodeDate(2009,11,28)+EncodeTime(14,23,12,000);
     //Your Code    
    end;
    

    The second option works because the TDatetime It is stored as a Double (TDateTime = type Double;), with the date as the integral part (the EncodeDate function returns the integral), and time as fractional part.

    The date part of the TDateTime represents the number of days that have passed since 12/30/1899. a TDateTime can be any date through 31 Dec 9999 (decimal value 2,958,465), TDateTime values can also be negative. The decimal value -693593 corresponds to 1 Jan 0001.

    see theses examples

    var
    myDateTime : TDateTime;
    
    Begin
    myDateTime :=0; //represents 12/30/1899
    myDateTime :=1; //represents 12/31/1899
    myDateTime :=-1; //represents 12/29/1899
    myDateTime :=-693593; //represents 01/01/0001
    myDateTime := Now(); //assign the current date and time to myDateTime 
    
    myDateTime:=Trunc(Now()); //Extract only the date part.
    
    myDateTime:=Frac(Now()); //Extract only the time part.
    
    myDateTime :=Now() + 1;// Add a day to the current datetime
    
    
    End;
    

    Important Note from embarcadero site :

    To find the fractional number of days
    between two dates, simply subtract the
    two values, unless one of the
    System.TDateTime values is negative.
    Similarly, to increment a date and
    time value by a certain fractional
    number of days, add the fractional
    number to the date and time value if
    the System.TDateTime value is
    positive.

    When working with negative
    System.TDateTime values, computations
    must handle time portion separately
    .
    The fractional part reflects the
    fraction of a 24-hour day without
    regard to the sign of the
    System.TDateTime value. For example,
    6:00 am on 12/29/1899 is –1.25, not –1
    + 0.25, which would be –0.75. There are no System.TDateTime values between
    –1 and 0.

    for addtional information you can see this link

    • Delphi Date/Time Support
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.