Query using date_add and date_format

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Alpal
Forum Commoner
Posts: 39
Joined: Mon Jul 26, 2010 4:08 am

Query using date_add and date_format

Post by Alpal »

Hi
Am building an invoicing system in a small sporting associations website.

Have this query, it works fine.
SELECT date_format( inv_date, '%b %e, %Y' ) AS issuedate, DATE_ADD( inv_date, INTERVAL 14 DAY ) AS duedate, inv_id, inv_date
FROM inv_to

inv_date is a DATE column in the table.

What I would like to do is put these 2 parts of the query together so I have a "Due Date" 14 days after the "Issue Date" that is reformatted
"date_format( inv_date, '%b %e, %Y' ) --------DATE_ADD( inv_date, INTERVAL 14 DAY ) AS duedate

Hope this makes sense.
As always, thanks in advance for any assistance you can offer
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Query using date_add and date_format

Post by requinix »

Alpal wrote:What I would like to do is put these 2 parts of the query together so I have a "Due Date" 14 days after the "Issue Date" that is reformatted
It already is 14 days after the inv_date. Are you asking about getting it formatted the same way? Then use DATE_FORMAT in the same way (except inv_date is replaced with the DATE_ADD you have there now).
Alpal
Forum Commoner
Posts: 39
Joined: Mon Jul 26, 2010 4:08 am

Re: Query using date_add and date_format

Post by Alpal »

Thanks
That is what I want to do but do not know how to put it all together :banghead:
Alpal
Forum Commoner
Posts: 39
Joined: Mon Jul 26, 2010 4:08 am

Re: Query using date_add and date_format

Post by Alpal »

Resolved the problem using php

<?php $newDate = date("M d, Y", strtotime($row_inv_pay['duedate'])); echo $newDate; ?>

Obviously I use dreamweaver - the recordset name is inv_pay

Would have preferred to do it in the query though if anyone can assist would appreciate.
Post Reply