Jump to content

NiallFH

Members
  • Posts

    30
  • Joined

  • Last visited

Everything posted by NiallFH

  1. Absolutely fantastic Barand, thank you very much!
  2. MySQL version 4.0 I have two tables, invoices (a table of invoices) and invworks (the individual work carried out on each of the invoices) invoices invoice_id int(11) invoice_date date invoice_terms int(3) invoice_status int(1) invworks mworks_id int(11) mworks_con int(11) mworks_rate decimal(10,2) mworks_qty decimal(10,3) What I am trying to calculate in a query is the total sum of work completed that is OVERDUE. In the invoices table, the field 'invoice_terms' is a figure of days that the invoiced customer must pay the invoice by after the issue date, usually anything up to 60. 'invoice_status' is an integer, 1, 2 or 3; '2' being the appropriate status in this instance, as that indicates that it has been invoiced. In the invworks table, mworks_con corresponds with invoice_id to link the work to the invoice. mworks_rate is a decimal number showing the value of a unit of work and mworks_qty shows the quantity of those units to be completed in the overall work. What I want this query to do is to show the complete sum of work completed for all invoices that are PAST the invoice date + days specified in the terms. Therefore, I have now put together the following query: echo"<p>Overdue: "; $get_overdue_total = mysql_query(" SELECT SUM(W.mworks_rate * W.mworks_qty) AS total FROM val_invworks W, val_invoices N WHERE W.mworks_con = N.invoice_id AND N.invoice_status = 2 AND DATE_FORMAT(N.invoice_date,'%Y-%m-%d') + 30 days < CURDATE() ",$objConnect); while($ovdata = mysql_fetch_array($get_overdue_total)) { $total = number_format($ovdata['total'],2); echo"<b>£$total</b></p>"; } I have had a look at the mySQL manual and I am at a bit of a loss. Could anyone perhaps suggest the best way to write the WHERE clause, where I currently have DATE_FORMAT(N.invoice_date,'%Y-%m-%d') + 30 days < CURDATE() ?
  3. Thanks for that Barand. This works a treat! I have a related question however - is there a way to rearrange the format of the days into years, months and days?
  4. For clarification, I am using MySQL 5.0.
  5. Hi all, first time poster here, but long time beginner using PHP and MySQL to put together sports statistics sites. The one I'm working on just now has me befuddled. I've never really worked with dates in MySQL before, so this is new territory for me, but I've been reading into DATEDIFF to try to achieve the following: I have two tables. One with a list of players and one with a list of goals scored. What I want to display is ONE result for the player who was the YOUNGEST scorer of a goal. Within the tables, I have: PlayerID | PlayerName | PlayerDOB GoalID | GoalPlayerID | GoalMatchDate So, I'm assuming we're looking at the DATEDIFF between the MIN(GoalMatchDate) and the PlayerDOB, while PlayerID = GoalPlayerID. That being said, I'm completely at a loss on how to start to query this, most specifically, in terms of limiting it to one query and how to order it by the difference in the dates. Hopefully someone can put me on the right track or even be so kind as to post an example that I could follow.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.