Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 TDateTime does not set the field out of 1900


I have a Table, assume paradox but the issue is the same with all tables, and one of the fields is a DATE field. I get to the date field by using TDataSet.FieldByName ("MyDateField").AsString I read the string into a AnsiString and then create the TDateTime with the AnsiString (TDateTime dt (AnsiString)). then I decode the TDateTime to change the year to something in the 2000 and then set it back to the dataset using TDataSet.FieldByName("MyDateField").AsString=dt.DateString(); The field is then not set to the 2000 year but back to the 900 year. What the heck is the problem. Is TDateTime not year 2000 compliant?   

    No, TDateTime is absolutely year 2000 complient. The problem is that you are setting the field as a string and something is being lost in the process. What you need to do is read in the TDateTime as a TDateTime by using a TDateField or a TDateTimeField. Instead of this:

    AnsiString as = DataSet->FieldByName ("FieldName")->AsString;
    TDateTime dt (as, TDateTime::Date);
    short int y, m, d;
    dt.DecodeDate (&y, &d, &y);
    y = 200 ;
    TDateTime dt2 (y, m, d);
    DateSet->Edit ();
    DataSet->FieldByName ("FieldName")->AsString = dt2.DateString();
    Do this:
    TDateField *df = (TDateField*)DataSet->FieldByName ("FieldName");
    TDateTime dt = df->AsDateTime;
    short int y, m, d;
    dt.DecodeDate (&y, &d, &y);
    y = 200 ;
    TDateTime dt2 (y, m, d);
    DateSet->Edit ();
    df->AsDateTime = dt2;
    
    It will now work fine. Y.T.

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use