Calculate Days Worked

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • howzit

    Calculate Days Worked

    I have a set date in my MySQL database that records when a Sales Lead
    is established and I echo that date as $row_rsLead['lead_date'];

    I need to be able to calculate how many days that lead has existed.
    $row_rsLead['lead_date']; outputs as 2007-06-14.

    I have made numerous attempts to create a function that will calculate
    the days between the lead_date and today's date, but have made
    absolutely no headway. I am either stuck working between differing
    date formats or really strange numerical outputs.

    If there is a script someone is willing to share or point me in a
    direction that is good for a relative newcomer to PHP, I would be most
    grateful.

    Thanks folks.

  • Rami Elomaa

    #2
    Re: Calculate Days Worked

    howzit kirjoitti:
    I have a set date in my MySQL database that records when a Sales Lead
    is established and I echo that date as $row_rsLead['lead_date'];
    >
    I need to be able to calculate how many days that lead has existed.
    $row_rsLead['lead_date']; outputs as 2007-06-14.
    >
    I have made numerous attempts to create a function that will calculate
    the days between the lead_date and today's date, but have made
    absolutely no headway. I am either stuck working between differing
    date formats or really strange numerical outputs.
    >
    If there is a script someone is willing to share or point me in a
    direction that is good for a relative newcomer to PHP, I would be most
    grateful.
    >
    Thanks folks.
    >


    SELECT DATEDIFF(lead_d ate, NOW()) AS days

    Or something like that. Next time RTFM before asking.

    --
    Rami.Elomaa@gma il.com

    "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
    usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze

    Comment

    • howzit

      #3
      Re: Calculate Days Worked

      On Jun 14, 11:48 am, Rami Elomaa <rami.elo...@gm ail.comwrote:
      howzit kirjoitti:
      >
      >
      >
      I have a set date in my MySQL database that records when a Sales Lead
      is established and I echo that date as $row_rsLead['lead_date'];
      >
      I need to be able to calculate how many days that lead has existed.
      $row_rsLead['lead_date']; outputs as 2007-06-14.
      >
      I have made numerous attempts to create a function that will calculate
      the days between the lead_date and today's date, but have made
      absolutely no headway. I am either stuck working between differing
      date formats or really strange numerical outputs.
      >
      If there is a script someone is willing to share or point me in a
      direction that is good for a relative newcomer to PHP, I would be most
      grateful.
      >
      Thanks folks.
      >
      http://dev.mysql.com/doc/refman/5.0/...nctions.html#f...
      >
      SELECT DATEDIFF(lead_d ate, NOW()) AS days
      >
      Or something like that. Next time RTFM before asking.
      >
      --
      Rami.Elo...@gma il.com
      >
      "Wikipedia on vähän niinq internetin raamattu, kukaan ei pohjimmiltaan
      usko siihen ja kukaan ei tiedä mikä pitää paikkansa." -- z00ze
      The reason I posted here (as stated above) was the solutions I have
      read and researched were not working for me. I was not asking to be
      spoon fed - I asked for guidance and direction.

      No need to insinuate I haven't RTFM. If it is too much to help, keep
      your bitter thoughts to yourself - everyone has to start somewhere you
      dick!

      Comment

      • Michael Fesser

        #4
        Re: Calculate Days Worked

        ..oO(howzit)
        >The reason I posted here (as stated above) was the solutions I have
        >read and researched were not working for me. I was not asking to be
        >spoon fed - I asked for guidance and direction.
        You got an answer - does it work?

        Micha

        Comment

        • howzit

          #5
          Re: Calculate Days Worked

          On Jun 14, 1:48 pm, Michael Fesser <neti...@gmx.de wrote:
          .oO(howzit)
          >
          The reason I posted here (as stated above) was the solutions I have
          read and researched were not working for me. I was not asking to be
          spoon fed - I asked for guidance and direction.
          >
          You got an answer - does it work?
          >
          Micha
          I don't want to edit my SELECT statement - as his answer would
          suggest. I need the SELECT statement to stay as it is. I was hoping
          for a function that would manipulate the one instance that I am
          needing.

          Comment

          • Michael Fesser

            #6
            Re: Calculate Days Worked

            ..oO(howzit)
            >I don't want to edit my SELECT statement - as his answer would
            >suggest.
            Why not? That would be the easiest and most reliable way.
            >I need the SELECT statement to stay as it is.
            Whenever possible you should let the database do all the dirty work.
            It's very good at handling things like date calculations and does it
            much more efficient than PHP.
            >I was hoping
            >for a function that would manipulate the one instance that I am
            >needing.
            In PHP you would have to turn the date into a Unix timestamp (strtotime)
            and calculate the difference to the current date. Two things might
            become an issue in some situations:

            * daylight saving time
            * Unix timestamp restrictions (1970-2038 on many systems)

            There's also a calendar extension in PHP for doing Gregorian and Julian
            date calculations, but this is not always available.

            So, as said, let the DB do it if possible.

            Micha

            Comment

            • howzit

              #7
              Re: Calculate Days Worked

              On Jun 14, 2:23 pm, Michael Fesser <neti...@gmx.de wrote:
              .oO(howzit)
              >
              I don't want to edit my SELECT statement - as his answer would
              suggest.
              >
              Why not? That would be the easiest and most reliable way.
              >
              I need the SELECT statement to stay as it is.
              >
              Whenever possible you should let the database do all the dirty work.
              It's very good at handling things like date calculations and does it
              much more efficient than PHP.
              >
              I was hoping
              for a function that would manipulate the one instance that I am
              needing.
              >
              In PHP you would have to turn the date into a Unix timestamp (strtotime)
              and calculate the difference to the current date. Two things might
              become an issue in some situations:
              >
              * daylight saving time
              * Unix timestamp restrictions (1970-2038 on many systems)
              >
              There's also a calendar extension in PHP for doing Gregorian and Julian
              date calculations, but this is not always available.
              >
              So, as said, let the DB do it if possible.
              >
              Micha
              Sound advice - I do appreciate your input. I will give it a shot -
              and post back my progress. Thanks!

              Comment

              • keychain

                #8
                Re: Calculate Days Worked

                "howzit" <jimpearce@gmai l.comwrote in message
                news:1181843030 .832620.252810@ z28g2000prd.goo glegroups.com.. .
                >I have a set date in my MySQL database that records when a Sales Lead
                is established and I echo that date as $row_rsLead['lead_date'];
                >
                I need to be able to calculate how many days that lead has existed.
                $row_rsLead['lead_date']; outputs as 2007-06-14.
                >
                I have made numerous attempts to create a function that will calculate
                the days between the lead_date and today's date, but have made
                absolutely no headway. I am either stuck working between differing
                date formats or really strange numerical outputs.
                >
                If there is a script someone is willing to share or point me in a
                direction that is good for a relative newcomer to PHP, I would be most
                grateful.
                >
                Thanks folks.
                >
                Another method is to use INT for date values, which makes it a breeze to
                calculate the difference between 2 dates.


                Comment

                • Rami Elomaa

                  #9
                  Re: Calculate Days Worked

                  "howzit" <jimpearce@gmai l.comwrote in message
                  news:1181847829 .369664.295800@ i13g2000prf.goo glegroups.com.. .
                  On Jun 14, 11:48 am, Rami Elomaa <rami.elo...@gm ail.comwrote:
                  howzit kirjoitti:


                  I have a set date in my MySQL database that records when a Sales Lead
                  is established and I echo that date as $row_rsLead['lead_date'];
                  I need to be able to calculate how many days that lead has existed.
                  $row_rsLead['lead_date']; outputs as 2007-06-14.
                  I have made numerous attempts to create a function that will calculate
                  the days between the lead_date and today's date, but have made
                  absolutely no headway. I am either stuck working between differing
                  date formats or really strange numerical outputs.
                  If there is a script someone is willing to share or point me in a
                  direction that is good for a relative newcomer to PHP, I would be most
                  grateful.
                  Thanks folks.
                  http://dev.mysql.com/doc/refman/5.0/...nctions.html#f...

                  SELECT DATEDIFF(lead_d ate, NOW()) AS days

                  Or something like that. Next time RTFM before asking.
                  >
                  The reason I posted here (as stated above) was the solutions I have
                  read and researched were not working for me. I was not asking to be
                  spoon fed - I asked for guidance and direction.
                  Well you got both guidance and direction: a perfectly good solution and a
                  link to the correct manual page. I don't understand why you're upset.
                  No need to insinuate I haven't RTFM. If it is too much to help, keep
                  your bitter thoughts to yourself - everyone has to start somewhere you
                  dick!
                  What we have here is a failure to communicate. Nothing in your original post
                  indicated that you had in fact read the manual. You stated that you've made
                  numerous attempts to _create a function_, as in, not looking in the manual
                  or finding other solutions. That is why I suggested that you should next
                  time Read The Fine Manual before asking.

                  --
                  Rami.Elomaa@gma il.com

                  "Good tea. Nice house." -- Worf


                  Comment

                  • Michael Fesser

                    #10
                    Re: Calculate Days Worked

                    ..oO(keychain)
                    >Another method is to use INT for date values, which makes it a breeze to
                    >calculate the difference between 2 dates.
                    Bad idea. What do you want to store there - days, hours, seconds? What
                    about daylight saving times and leap years?

                    Micha

                    Comment

                    Working...