Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

php - Variable vs. Text Subtraction

  • 22-01-2003 11:07am
    #1
    Registered Users, Registered Users 2 Posts: 1,068 ✭✭✭


    I've just started doing some simple php, and want to know is it possible to subtract a "text-value" (for want of a better term) from a variable, i.e.

    <td><center>31/1</center></td>

    I have the date 31st of Janurary in a table column (as above), and I have another variable called "$mday" ( from getdate() ) which holds today's date in numerical format, e.g. 22

    So, if I declare a new variable "$total", how do I initalise it do subtract $mday from 31? Or is that even possible?

    If it's not possible, no problem, as I can just declare 31 as a variable, but I'm curious now just to see if this can be done :)


Comments

  • Registered Users, Registered Users 2 Posts: 1,709 ✭✭✭Balfa


    i don't quite get what you want to do.

    if you want to initialise $total as 31 - $mday, wouldn't you just do $total = 31 - $mday?

    *boggle* :/


  • Registered Users, Registered Users 2 Posts: 1,068 ✭✭✭Magic Monkey


    Yes, thanks, that actually makes more sense to use now, d'oh! :)

    But what I meant originally was could you point to the table column that contains the text-value instead of explicitly typing it, e.g.

    $total = $name - $mday
    Where "$name" would be the name of the table column (um, that is, if you could name it).

    You know, I'm probably just making a mountain out of a molehill here :p


  • Registered Users, Registered Users 2 Posts: 1,709 ✭✭✭Balfa


    i'm not sure if you can do _that_, but you could define that as another variable, so you can have something like:

    $tabledate = 31
    <td><center><? $tabledate ?>/1</center></td>
    // the above line will insert the value for tabledate in
    // where you manually typed 31 before
    $total = $tabledate - $mday


    that any help?


  • Registered Users, Registered Users 2 Posts: 1,068 ✭✭✭Magic Monkey


    Originally posted by Balfa
    i'm not sure if you can do _that_, but you could define that as another variable, so you can have something like:

    $tabledate = 31
    <td><center><? $tabledate ?>/1</center></td>
    // the above line will insert the value for tabledate in
    // where you manually typed 31 before
    $total = $tabledate - $mday


    that any help?

    Heh, funnily enough that's what I ended up doing just a few minutes ago :D
    Except that the $tabledate is "31/1" in my code, and when I do $tabledate - $mday (22) I get 9, which is right. It must ignore the /1 for some reason.

    While you're here, you don't know anything about date subtraction, do you? ;)


  • Closed Accounts Posts: 19,777 ✭✭✭✭The Corinthian


    Originally posted by Magic Monkey
    While you're here, you don't know anything about date subtraction, do you? ;)
    You may find the mktime useful for that. Otherwise I would reccomend you avoid using datetime types such as MySQL DATETIME and use only UNIX timestamps.

    Beyond that, you should RTFM on PHP Date/Time functions. Hope this helped.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 1,068 ✭✭✭Magic Monkey


    Originally posted by The Corinthian
    You may find the mktime useful for that. Otherwise I would reccomend you avoid using datetime types such as MySQL DATETIME and use only UNIX timestamps.

    Beyond that, you should RTFM on PHP Date/Time functions. Hope this helped.

    Thanks Corinthian,

    I found a good tutorial here, that I'm reading ATM. Yeah, DATETIME wouldn't be appropriate in this case, and time() seems to be extremley flexible, so it's all cool.


Advertisement