Increment Date field every day

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajd335
    New Member
    • Apr 2008
    • 123

    Increment Date field every day

    Hi all,

    I am writing an application using PHP and MYSQL.

    I have one Employee table which contains date when the employee was created. after 10 days of creation date I wanted to send them some email/function. how can I do so???? .. I mean how can it be done ?? What I need is I wanted to run some cron job or any thing(not sure what to use) so that when I fetch the date from table , gives me that 10 days are passed since you created the account..


    Thanks,
    Ajd335
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    If you want your application to automatically send an email, or something similar, then you would indeed need to schedule a daily (or more frequent) execution of some script, which would then do the actual task.

    On Unix systems that would be done using crontab.
    On Windows it would be the Windows Task Scheduler.
    (Google has a lot of info on this, by the way)

    However, if you only need to update the data inside MySQL, the latest versions of MySQL (5.1.6 and later) do offer a time scheduler, which can handle such tasks.
    See 19.4. Using the Event Scheduler

    Comment

    • ajd335
      New Member
      • Apr 2008
      • 123

      #3
      Originally posted by Atli
      Hi.

      If you want your application to automatically send an email, or something similar, then you would indeed need to schedule a daily (or more frequent) execution of some script, which would then do the actual task.

      On Unix systems that would be done using crontab.
      On Windows it would be the Windows Task Scheduler.
      (Google has a lot of info on this, by the way)

      However, if you only need to update the data inside MySQL, the latest versions of MySQL (5.1.6 and later) do offer a time scheduler, which can handle such tasks.
      See 19.4. Using the Event Scheduler
      Hi Atli,

      Thanks a lot. yes that was something I was looking for....Thanks again

      Actually in my PHP script I am writting a query to check the status of usagectr which contains the number of days since creation( Date field gives the value of creation date and usagectr is number of day used). I am checking if they are greater than 10 then I am changing value of one other field.

      Creating Event will work but I am not sure ...should I write that in my PHP page or what??? I dont know much about cron jobs....Can you please help me...


      Thanks again...

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Ok.

        Cron jobs are separate from your website. They are basically just Unix commands, executed at a preset interval, usually used to execute script files.

        To set up a cron job to execute a PHP script, you need to:
        1. Install PHP CLI support (if it isn't already installed).
          How you do this depends on the Unix/Linux distro you use, but this is often provided through the distro's package manager.
        2. Create the script you want to execute. This does not need to output anything, as any output will simple be discarded. (This is a background operation.)
          If you want to log the results of your script, you will need to do that manually. (By writing it to a log file, for example)
        3. Add the cron job by editing the crontab.
          Simply doing: "$ crontab -e" should work. (Does for my Ubuntu server, anyways :P)

          This will bring up a file for you to edit, which originally should look somewhat like:
          Code:
          # m h  dom mon dow   command
          You will have to add the command you want executed, along with the interval at which you want it executed.
          For example:
          Code:
          # m h  dom mon dow   command
            0 6  *   *   *     php ~/someScript.php
          This will execute a script called "someScript.php " in the user's folder every morning at 06:00.

          See the Wikipedia entry for more details on the file

        And that should be it.

        Comment

        • ajd335
          New Member
          • Apr 2008
          • 123

          #5
          Originally posted by Atli
          Ok.

          Cron jobs are separate from your website. They are basically just Unix commands, executed at a preset interval, usually used to execute script files.

          To set up a cron job to execute a PHP script, you need to:
          1. Install PHP CLI support (if it isn't already installed).
            How you do this depends on the Unix/Linux distro you use, but this is often provided through the distro's package manager.
          2. Create the script you want to execute. This does not need to output anything, as any output will simple be discarded. (This is a background operation.)
            If you want to log the results of your script, you will need to do that manually. (By writing it to a log file, for example)
          3. Add the cron job by editing the crontab.
            Simply doing: "$ crontab -e" should work. (Does for my Ubuntu server, anyways :P)

            This will bring up a file for you to edit, which originally should look somewhat like:
            Code:
            # m h  dom mon dow   command
            You will have to add the command you want executed, along with the interval at which you want it executed.
            For example:
            Code:
            # m h  dom mon dow   command
              0 6  *   *   *     php ~/someScript.php
            This will execute a script called "someScript.php " in the user's folder every morning at 06:00.

            See the Wikipedia entry for more details on the file

          And that should be it.
          Hi Atli,

          Thanks alot for the information.

          That helped :)..... Thanks alot again..

          Comment

          Working...