Date Type Modification - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Date Type Modification

I used Date Type for my date fields:

...

DateOfBirth:TdateTime;

...

BUT you have to write month/date/year or else an error message appears;

How can i change it to date/month/year?

Comments

  • zibadianzibadian Posts: 6,349Member
    : I used Date Type for my date fields:
    :
    : ...
    :
    : DateOfBirth:TdateTime;
    :
    : ...
    :
    : BUT you have to write month/date/year or else an error message appears;
    :
    : How can i change it to date/month/year?
    :
    You can create your own date string parser, which gives you 3 integer variable. It's not that difficult. Then you can use EncodeDate() to fill the TDateTime variable with the integer values.
  • sarkiemarkiesarkiemarkie Posts: 89Member
    : : I used Date Type for my date fields:
    : :
    : : ...
    : :
    : : DateOfBirth:TdateTime;
    : :
    : : ...
    : :
    : : BUT you have to write month/date/year or else an error message appears;
    : :
    : : How can i change it to date/month/year?
    : :
    : You can create your own date string parser, which gives you 3 integer variable. It's not that difficult. Then you can use EncodeDate() to fill the TDateTime variable with the integer values.
    :

    Can you tell me exactly how to do it. I have no idea

  • zibadianzibadian Posts: 6,349Member
    : : : I used Date Type for my date fields:
    : : :
    : : : ...
    : : :
    : : : DateOfBirth:TdateTime;
    : : :
    : : : ...
    : : :
    : : : BUT you have to write month/date/year or else an error message appears;
    : : :
    : : : How can i change it to date/month/year?
    : : :
    : : You can create your own date string parser, which gives you 3 integer variable. It's not that difficult. Then you can use EncodeDate() to fill the TDateTime variable with the integer values.
    : :
    :
    : Can you tell me exactly how to do it. I have no idea
    :
    :
    If each of the number is always 2 digits long then this code should work:
    [code]
    Day := StrToInt(DateStr[1]+DateStr[2]);
    Month := StrToInt(DateStr[4]+DateStr[5]);
    Year := StrToInt(DateStr[7]+DateStr[8]);
    Date := EncodeDate(Year, Month, Day);
    [/code]
    If there is variation in the formatting (like 4 digits per year, or 1 per day/month) then you'll need to design a better parser.
  • sarkiemarkiesarkiemarkie Posts: 89Member
    : : : : I used Date Type for my date fields:
    : : : :
    : : : : ...
    : : : :
    : : : : DateOfBirth:TdateTime;
    : : : :
    : : : : ...
    : : : :
    : : : : BUT you have to write month/date/year or else an error message appears;
    : : : :
    : : : : How can i change it to date/month/year?
    : : : :
    : : : You can create your own date string parser, which gives you 3 integer variable. It's not that difficult. Then you can use EncodeDate() to fill the TDateTime variable with the integer values.
    : : :
    : :
    : : Can you tell me exactly how to do it. I have no idea
    : :
    : :
    : If each of the number is always 2 digits long then this code should work:
    : [code]
    : Day := StrToInt(DateStr[1]+DateStr[2]);
    : Month := StrToInt(DateStr[4]+DateStr[5]);
    : Year := StrToInt(DateStr[7]+DateStr[8]);
    : Date := EncodeDate(Year, Month, Day);
    : [/code]
    : If there is variation in the formatting (like 4 digits per year, or 1 per day/month) then you'll need to design a better parser.
    :
    where would i insert that code. parser is a completely new word for me
  • zibadianzibadian Posts: 6,349Member
    : : : : : I used Date Type for my date fields:
    : : : : :
    : : : : : ...
    : : : : :
    : : : : : DateOfBirth:TdateTime;
    : : : : :
    : : : : : ...
    : : : : :
    : : : : : BUT you have to write month/date/year or else an error message appears;
    : : : : :
    : : : : : How can i change it to date/month/year?
    : : : : :
    : : : : You can create your own date string parser, which gives you 3 integer variable. It's not that difficult. Then you can use EncodeDate() to fill the TDateTime variable with the integer values.
    : : : :
    : : :
    : : : Can you tell me exactly how to do it. I have no idea
    : : :
    : : :
    : : If each of the number is always 2 digits long then this code should work:
    : : [code]
    : : Day := StrToInt(DateStr[1]+DateStr[2]);
    : : Month := StrToInt(DateStr[4]+DateStr[5]);
    : : Year := StrToInt(DateStr[7]+DateStr[8]);
    : : Date := EncodeDate(Year, Month, Day);
    : : [/code]
    : : If there is variation in the formatting (like 4 digits per year, or 1 per day/month) then you'll need to design a better parser.
    : :
    : where would i insert that code. parser is a completely new word for me
    :
    A parser is a code or an object, which reads some data and can determine what it says. In this case the code I gave you here is a very simple parser which reads the variable DateStr and can convert it into an actual date in the memory.
    The Delphi compiler uses a parser object to read your source code and make sense of it, so that the compiler can change it into binary code.
  • sarkiemarkiesarkiemarkie Posts: 89Member
    : : : : : : I used Date Type for my date fields:
    : : : : : :
    : : : : : : ...
    : : : : : :
    : : : : : : DateOfBirth:TdateTime;
    : : : : : :
    : : : : : : ...
    : : : : : :
    : : : : : : BUT you have to write month/date/year or else an error message appears;
    : : : : : :
    : : : : : : How can i change it to date/month/year?
    : : : : : :
    : : : : : You can create your own date string parser, which gives you 3 integer variable. It's not that difficult. Then you can use EncodeDate() to fill the TDateTime variable with the integer values.
    : : : : :
    : : : :
    : : : : Can you tell me exactly how to do it. I have no idea
    : : : :
    : : : :
    : : : If each of the number is always 2 digits long then this code should work:
    : : : [code]
    : : : Day := StrToInt(DateStr[1]+DateStr[2]);
    : : : Month := StrToInt(DateStr[4]+DateStr[5]);
    : : : Year := StrToInt(DateStr[7]+DateStr[8]);
    : : : Date := EncodeDate(Year, Month, Day);
    : : : [/code]
    : : : If there is variation in the formatting (like 4 digits per year, or 1 per day/month) then you'll need to design a better parser.
    : : :
    : : where would i insert that code. parser is a completely new word for me
    : :
    : A parser is a code or an object, which reads some data and can determine what it says. In this case the code I gave you here is a very simple parser which reads the variable DateStr and can convert it into an actual date in the memory.
    : The Delphi compiler uses a parser object to read your source code and make sense of it, so that the compiler can change it into binary code.
    :
    there is actally a built in functon that i found.
Sign In or Register to comment.