3

I have a table called Students , in this table there is a date column called BirthDay with Date, abbreviated format (eg : 26/06/2017), the problem is in delphi the Field type is SQLTimeStamp, and I want to save just the Date not a DateTime.

DM.TStudentsBirthDay.Value := DateTimeToSQLTimeStamp(DateTimePicker1.Date);

That will post a DateTime.

How can I fix this? How can I insert just the date?

Update :

I try to do it with TFDQuery component and it works perfectly , also with TAODTable component.

Ilyes
  • 14,640
  • 4
  • 29
  • 55
  • What is `TStudentsBirthDay`? Which FireDAC component do you use? Do you use LiveBindings? – Victoria Jun 26 '17 at 10:09
  • `TStudents` is FireDac table , `BirthDay` is the field , I'm using `TFDTable` component , and no I'm not using LiveBindings. – Ilyes Jun 26 '17 at 10:12
  • Thanks for the info, though my question might have been pointless. I'm afraid, FireDAC is correct here, the DATE data type is in ODBC mapped to [SQL_TIMESTAMP](https://learn.microsoft.com/en-us/sql/odbc/microsoft/microsoft-access-data-types). – Victoria Jun 26 '17 at 10:26
  • @Victoria Alright , So I can't insert just the date with firedac components? is that what you try to say? – Ilyes Jun 26 '17 at 10:28
  • Try to define the field definition as be `TDateField` then. – Victoria Jun 26 '17 at 10:47
  • That w'll not work – Ilyes Jun 26 '17 at 10:50
  • You are right, sorry. So long the table is populated by MS Access schema, it will be `SQL_TIMESTAMP` data type. Of course with `TFDQuery` you can access parameters by specific types where can FireDAC cut off proper portion (or use macros), but doesn't change anything on internal storage of MS Access of such value (I guess it's so because I haven't found separate data types). I would leave your question on someone else. – Victoria Jun 26 '17 at 11:28
  • As far as I know, Access always stores date/time fields as date + time. It just doesn't display the time part if it's set to 00:00:00 and the time part isn't explicitly displayed. As long as you adjust your code to set the time portion to that, you shouldn't have a problem. – Erik A Jun 26 '17 at 11:59
  • Use `DM.TStudentsBirthDay.Value := DateTimeToSQLTimeStamp(DateOf(DateTimePicker1.Date));` to remove time potion from the date time picker, or simply set the date time in the picker to midnight. see http://docwiki.embarcadero.com/Libraries/Berlin/en/System.DateUtils.DateOf – Gerry Coll Jun 26 '17 at 12:10
  • @Erik, thanks for confirming single data type for date/time values. But adding e.g. 12 hours to 26/06/2017 23:00:00 and 26/06/2017 06:00:00 and working with the resulting date portion later makes a difference. So, it can make sense to reset the time portion to midnight. – Victoria Jun 26 '17 at 19:15

1 Answers1

2

Thanks for @Gerry Coll for the comment.

Using DateTimeToSQLTimeStamp() and DateOf() functions:

DM.TStudentsBirthDay.Value := DateTimeToSQLTimeStamp(DateOf(DateTimePicker1.Date));

That works perfectly.

Ilyes
  • 14,640
  • 4
  • 29
  • 55