MDY Function

The MDY function takes as its arguments three integer expressions that represent the month, day, and year, and returns a type DATE value.

  • The first argument represents the number of the month (1 to 12).
  • The second argument represents the number of the day of the month (1 to 28, 29, 30, or 31, as appropriate for the month).
  • The third argument represents the 4-digit year. You cannot use a 2-digit abbreviation.

Example of the MDY function in an UPDATE statement

The following example updates a row in the orders table whose purchase-order number is 8052 by changing its paid_date column value to the first day of the current month:
UPDATE orders SET paid_date = MDY(MONTH(TODAY), 1, YEAR(TODAY))
   WHERE po_num = '8052';
Here the first and last arguments to the MDY function are time expressions that return integers corresponding to the current month and year. The second argument specifies the day of the month as a literal integer. Reversing the order of the first two arguments in this example would change the paid_date value to some day before January 13 of the current year, unless the same application also included error-checking code that identified that date as too early to be valid.