user3687952
user3687952

Reputation:

mysql data type for date and invoice

I'm new in MySQL and I've got a problem: I want to create table INVOICES, that contains columns:

DATE - I know, it's easy to use DATE data type, but is there any way to display date in format dd.mm.yyyy?

INVOICE_ID: which should be in format I/dd/mm/yyyy i.e. I/5/11/2014. The letter I means invoice, the rest is a date.

Upvotes: 0

Views: 1321

Answers (1)

Kermit
Kermit

Reputation: 34053

You always store in the native format of the database and then use the built-in date functions to manipulate the format. In your case, you would use DATE_FORMAT():

 DATE_FORMAT(date,format)

Formats the date value according to the format string.

The documentation provides a table of specifiers to output in your desired format.

To output in your desired format, you would use:

SELECT DATE_FORMAT(your_date_column, 'I/%c/%e/%Y');

Which gives you

| DATE_FORMAT(your_date_column, 'I/%C/%E/%Y') |
|---------------------------------------------|
|                                 I/5/29/2014 |

See it in action

Upvotes: 1

Related Questions