List:General Discussion« Previous MessageNext Message »
From:Douglas Brantz Date:June 4 2000 3:38pm
Subject:Re: Question about subtracting from timestamp
View as plain text  
Would this work?
Here is an example that uses date functions. The query below selects all
records with a date_col value from within the last 30 days:

mysql> SELECT something FROM table
           WHERE TO_DAYS(NOW()) - TO_DAYS(date_col) <= 30;

and I can just have a variable for the number of days?
Except, I am not using date_col  I have timestamps - would this do the same
thing.
Basically, just need to grab all the records from a record that fall between
current date and number of days select by the admin.  I always make this more
difficult that it needs to be.

Thanks

Douglas

Douglas Brantz wrote:

> I am trying to use this code to help me: It doesn't work when  I try to
> subtract 6 days from today.
> It works if it stays within the same month - for example 2 works fine.??
> mysql> select date_format((curdate()-6),'%Y-%m-%d');
> +---------------------------------------+
> | date_format((curdate()-6),'%Y-%m-%d') |
> +---------------------------------------+
> | NULL                                  |
> +---------------------------------------+
> 1 row in set (0.00 sec)
>
> Am I going to have to figure this out with Unix Time or UNIX_TIMESTAMPS??
>
> Douglas Brantz wrote:
>
> > I have a timeclock program running with Mysql and would like to know if
> > its possible to do a simple subtraction on the timestamp.
> >
> > Basically when the admin wants to check time card history of the student
> > workers I have a drop down menu of all the students and then I would
> > like to have two choices 1. complete history and 2. how many days from
> > current day.
> >
> > 1.  With the complete history I can simply grab the timestamp when the
> > user was created and current date.
> >
> > 2.  WIth how many days back - say 1 week - is there an easy way to
> > subtract 7 days or 1 week from a current timestamp and I guess the
> > timestamp would be the current date/time?
> >
> > So,  Now( ) - 7 days?  and how would that be written out?
> > Then I need to grab the result of the created timestamp-7 days and
> > do a between statement show all records from student that fall between
> > the $now ( ) -7 days  and
> > Now( )?
> >
> > Thansk,
> >
> > Douglas
> >
> > --
> > ---------------------------------------------------------------------
> > Please check "http://www.mysql.com/php/manual.php3" before
> > posting. To request this thread, e-mail mysql-thread39276@stripped
> >
> > To unsubscribe, send a message to:
> >     <mysql-unsubscribe-brantzdr=appstate.edu@stripped>
>
> --
> ---------------------------------------------------------------------
> Please check "http://www.mysql.com/php/manual.php3" before
> posting. To request this thread, e-mail mysql-thread39278@stripped
>
> To unsubscribe, send a message to:
>     <mysql-unsubscribe-brantzdr=appstate.edu@stripped>

Thread
Question about subtracting from timestampDouglas Brantz4 Jun
  • Re: Question about subtracting from timestampDouglas Brantz4 Jun
    • RE: Question about subtracting from timestampSander Pilon4 Jun
  • RE: Question about subtracting from timestampSander Pilon4 Jun
  • Re: Question about subtracting from timestampDouglas Brantz4 Jun
  • subtracting from timestampDouglas Brantz4 Jun