Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Simple Query Help Requested
Hello:

I have developed a MySQL database that outputs of garage sales in a
neighborhood. One of the fields obviously is the the date of the garage
sale. I have called that field "date" and the table name is "garagesale".
When the output script is called, I would like any garage sales that have
already taken place to drop off of the output list. I know it involves a
query that will not display any record where date < today's date, but I am
having trouble putting it together. If someone could help me out I would
greatly appreciate it. Thank you in advance.

David



Report this thread to moderator Post Follow-up to this message
Old Post
C. David Rossen
11-21-04 01:55 AM


Re: Simple Query Help Requested
Try making your date a Unix timestamp.  It makes comparing dates so much
easier.  I just discovered this method and I would never go back.   PHP has
some wonderful functions for this.  Research it.


$todaysdate = time();
$sql = "SELECT * FROM garagesale WHERE date > '$todaysdate'";
$query = mysql_query($sql);

................. or something along those lines.



"C. David Rossen" <cdrossen@cdrmarketing.com> wrote in message
news:TJKdnfYwzuk1RwLcRVn-vw@comcast.com...
> Hello:
>
> I have developed a MySQL database that outputs of garage sales in a
> neighborhood. One of the fields obviously is the the date of the garage
> sale. I have called that field "date" and the table name is "garagesale".
> When the output script is called, I would like any garage sales that have
> already taken place to drop off of the output list. I know it involves a
> query that will not display any record where date < today's date, but I am
> having trouble putting it together. If someone could help me out I would
> greatly appreciate it. Thank you in advance.
>
> David
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Jim Marnott
11-21-04 08:57 AM


Re: Simple Query Help Requested
If you don't want to keep the old dates in the table any more, you could
run a query first that deletes them, or maybe moves them to an
"old_dates" table - for archiving.

Still requires using date as an index - and 'd go with Jim's suggestion
too - so much simpler.

Jim Evans (no relation)

Jim Marnott wrote:
> Try making your date a Unix timestamp.  It makes comparing dates so much
> easier.  I just discovered this method and I would never go back.   PHP ha
s
> some wonderful functions for this.  Research it.
>
>
> $todaysdate = time();
> $sql = "SELECT * FROM garagesale WHERE date > '$todaysdate'";
> $query = mysql_query($sql);
>
> ................. or something along those lines.
>
>
>
> "C. David Rossen" <cdrossen@cdrmarketing.com> wrote in message
> news:TJKdnfYwzuk1RwLcRVn-vw@comcast.com...
> 
>
>
>

Report this thread to moderator Post Follow-up to this message
Old Post
Jim Evans
11-21-04 01:55 PM


Re: Simple Query Help Requested
Jim and Jim:

Thanks for the help. When you say making date a Unix timestamp, are you
talking about changing it from varchar to timestamp? Thank you.

David

"Jim Evans" <longhairedjim@ntlworld.com> wrote in message
news:P1Ynd.10$W91.2@newsfe5-win.ntli.net...
> If you don't want to keep the old dates in the table any more, you could
> run a query first that deletes them, or maybe moves them to an
> "old_dates" table - for archiving.
>
> Still requires using date as an index - and 'd go with Jim's suggestion
> too - so much simpler.
>
> Jim Evans (no relation)
>
> Jim Marnott wrote: 
has 
"garagesale". 
have 
am 



Report this thread to moderator Post Follow-up to this message
Old Post
C. David Rossen
11-22-04 08:57 AM


Re: Simple Query Help Requested
No.  Mysql timestamp and unix timestamp are very different things.  A Mysql
timestamp is something like "20040706" (ie: just a regular date) where a
Unix timestamp is the number of seconds since Jan 1, 1970.  Unix timsetamps
may not look very pretty, but you can do comparisons and date "math" very
easily because it's just a matter of simple addition and subtraction.

eg: If it's now 1101093660, you know tomorrow will be 1101093660 + 86400
because there are 86400 seconds in 24 hours.

One very important thing to remember when working with UNIX timestamps and
Mysql is that your timestamp column must be INT.  Otherwise comparisons
become difficult, if not impossible.  I once spent hours trying to debug
date comparison code that just wouldn't work, when It finally dawned on me
to check the column type.

JM


"C. David Rossen" <cdrossen@cdrmarketing.com> wrote in message
news:z5OdnbT8k64poTzcRVn-jw@comcast.com...
> Jim and Jim:
>
> Thanks for the help. When you say making date a Unix timestamp, are you
> talking about changing it from varchar to timestamp? Thank you.
>
> David
>
> "Jim Evans" <longhairedjim@ntlworld.com> wrote in message
> news:P1Ynd.10$W91.2@newsfe5-win.ntli.net... 
> has 
> "garagesale". 
> have 
> am 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Jim Marnott
11-22-04 08:57 AM


Re: Simple Query Help Requested
Acutally, there are 4 fields which involve the dates and times of 2 days
(all garage sales are two days). In the php output, here iw what I have:

$date1=mysql_result($result,$i,"date1");
$date2=mysql_result($result,$i,"date2");
$time1=mysql_result($result,$i,"time1");
$time2=mysql_result($result,$i,"time2");

This displays the data captured from the html form that I have. date1 &
date2 are date fields and time1 and time2 are time fields. How would I
display them? For example, date1 is now displaying like 2004-12-03. I
understand that because that is how a date field is formatted in MySQL. But
how would I get it to display, something like: Friday, 12/03/04? Same with
time...how would I format it to display say 9:00 AM instead of 09:00:00?
Thanks.

David

"Jim Marnott" <sdlkj@lkj.com> wrote in message
news:H_bod.12121$yx6.489374@weber.videotron.net...
> No.  Mysql timestamp and unix timestamp are very different things.  A
Mysql
> timestamp is something like "20040706" (ie: just a regular date) where a
> Unix timestamp is the number of seconds since Jan 1, 1970.  Unix
timsetamps
> may not look very pretty, but you can do comparisons and date "math" very
> easily because it's just a matter of simple addition and subtraction.
>
> eg: If it's now 1101093660, you know tomorrow will be 1101093660 + 86400
> because there are 86400 seconds in 24 hours.
>
> One very important thing to remember when working with UNIX timestamps and
> Mysql is that your timestamp column must be INT.  Otherwise comparisons
> become difficult, if not impossible.  I once spent hours trying to debug
> date comparison code that just wouldn't work, when It finally dawned on me
> to check the column type.
>
> JM
>
>
> "C. David Rossen" <cdrossen@cdrmarketing.com> wrote in message
> news:z5OdnbT8k64poTzcRVn-jw@comcast.com... 
could 
PHP 
garage 
involves 
I 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
C. David Rossen
11-23-04 08:56 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP SQL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:23 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.