0

I have a field date name modified.

My goal to get date update with format MM-DD-YYYY when insert or update records.

In the property, I set datatype = date and on the date value and binding option of this field, how to I set to get the date format MMDDYYYY

If I use (getdate) then I got format YYYYDDMM

The reason I asked because I have the query that I want to select the current month

SELECT  modified
   from  Contact
   where modified >= Dateadd(Month, Datediff(Month, 0, DATEADD(m, -1, current_timestamp)), 0)

Can you correct this query if the date format YYYYDDMM
Thank you.

Tsang
  • 109
  • 10
  • 8
    Short answer: DATE or DATETIME doesn't have a format, unless you're looking to store it as strings instead of binary data which is very bad idea. – Ilyes Apr 08 '20 at 20:37
  • I can convert the current date format to MMDDYYYY but i like to replace the current format . – Tsang Apr 08 '20 at 20:41
  • 2
    Just to add to @Sami's comment, you can impose whatever format you like on the date when you query the data from the table. – Eric Brandt Apr 08 '20 at 20:41
  • 3
    `Date`, `DateTime`, and `DateTime2` types do not have a format and are not stored as a formatted string. You only perceive a format because you are human so the default display shows you the value formatted in ISO8601 notation. The displayed format is not a concern of the persistence layer, it is a concern for the presentation layer where the value is rendered for a human to see it. – Igor Apr 08 '20 at 20:42
  • Thank you all for help – Tsang Apr 08 '20 at 20:44
  • you can change the format look at this question for reference: https://stackoverflow.com/questions/16645607/how-to-use-convert-function-in-sql-server – Rishi Apr 08 '20 at 20:45
  • Thanks Rishi. I can use that, just some more work. – Tsang Apr 08 '20 at 20:57
  • So the column `modified` is stored as `varchar` instead of `date`? – Dale K Apr 08 '20 at 21:11
  • i can use both if if work – Tsang Apr 08 '20 at 21:21

0 Answers0