473,578 Members | 2,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP-MySQL DateQuestion

Hi,

I´d like to display anniversary greetings on my website. The annyversaries
are saved in a mysql-table in the mysql DATE-Format (YYYY-MM-DD). Now I need
to select all rows where the day and the month is between now and +7 days
(to show the anniversaries coming up within the next week). My question is:
Is there a way to select these rows directly from the DB without recognizing
the year? Or do I have to query all rows and parse the dates in code?
Any help appreciated!

Thanks in advance,

Hinrich
Jul 17 '05 #1
5 6336
<?php

$day = date("Y-m-d");
$day_seven = date("Y-m-d", mktime(0,0,0, date(m), date(d)+7,date( Y)));

$sql = "SELECT * FROM your_table WHERE date_column >= ".$day." AND <=
$day_seven";

?>
--
Sugapablo
------------------------------------
http://www.sugapablo.com <--music
http://www.sugapablo.net <--personal

Jul 17 '05 #2
Sugapablo wrote:
$sql = "SELECT * FROM your_table WHERE date_column >= ".$day." AND <=
".$day_seve n;


^ better.

--
Sugapablo
------------------------------------
http://www.sugapablo.com <--music
http://www.sugapablo.net <--personal

Jul 17 '05 #3
Thanks for your answer, but I´m afraid that won´t work...

in your example $day looks like "2003-09-25",
the entries in date_column look like "1974-12-15", ...
this means the value in date_column could never be greater than $day (except
in the case I can foresee a birth, but that happens quite seldom,
unfortunately).
That´s why I asked if there´s a way to build a select where the Year in the
date_column is NOT recognized...

Hinrich

"Sugapablo" <ru********@sug apablo.com> schrieb im Newsbeitrag
news:vn******** ****@corp.super news.com...
Sugapablo wrote:
$sql = "SELECT * FROM your_table WHERE date_column >= ".$day." AND <=
".$day_seve n;


^ better.

--
Sugapablo
------------------------------------
http://www.sugapablo.com <--music
http://www.sugapablo.net <--personal

Jul 17 '05 #4
Hinrich Specht wrote:
Hi,

I´d like to display anniversary greetings on my website. The annyversaries
are saved in a mysql-table in the mysql DATE-Format (YYYY-MM-DD). Now I need
to select all rows where the day and the month is between now and +7 days
(to show the anniversaries coming up within the next week). My question is:
Is there a way to select these rows directly from the DB without recognizing
the year? Or do I have to query all rows and parse the dates in code?
Any help appreciated!


slight tweaking of dates :)

<?php
$now0 = date('m')*100+d ate('d');
$now7 = date('m', time()+7*24*60* 60)*100+date('d ', time()+7*24*60* 60);
?>

and build the sql with $now0 and $now7

select x, y, z
from yourtable
where month(datefield )*100+day(datef ield) between $now0 and $now7
Happy Coding :)

--
I have a spam filter working.
To mail me include "urkxvq" (with or without the quotes)
in the subject line, or your mail will be ruthlessly discarded.
Jul 17 '05 #5

On 25-Sep-2003, "Hinrich Specht" <hs*******@gmx. de> wrote:
I´d like to display anniversary greetings on my website. The annyversaries
are saved in a mysql-table in the mysql DATE-Format (YYYY-MM-DD). Now I
need
to select all rows where the day and the month is between now and +7 days
(to show the anniversaries coming up within the next week). My question
is:
Is there a way to select these rows directly from the DB without
recognizing
the year? Or do I have to query all rows and parse the dates in code?
Any help appreciated!


The following will work for every thing but the anniversaries in first week
of the year:
select * from mytable where dayofyear(anniv date)>=dayofyea r(curdate()) and
dayofyear(anniv date)<=dayofyea r(curdate())+7

to cover it you need
select * from mytable where (dayofyear(anni vdate)>=dayofye ar(curdate()) and
dayofyear(anniv date)<=dayofyea r(curdate())+7) or
(dayofyear(anni vdate)+365>=day ofyear(curdate( )) and
dayofyear(anniv date)+365<=dayo fyear(curdate() )+7)

This still ignores the problem of leap years, but I'll leave that up to you.
--
Tom Thackrey
www.creative-light.com
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
4036
by: lawrence | last post by:
I haven't been able to reach www.php.net for days. Most of the rest of the web is working for me, though I've bad trouble reaching any English sites. Anyone else having trouble?
9
2632
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php'; global $LOGINDIR;
59
6971
by: Lennart Björk | last post by:
Hi All, I have a tiny program: <!doctype HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>MyTitle</title> <meta http-equiv="Content-Type" content="text/html;
8
4029
by: Marcel | last post by:
I have a problem with a PHP page that seems to get executed twice. I am running PHP5 ISAPI on 2003 server. The script is a PHP page with a form. When the form is submitted one record have to be inserted in the database but when i look at the database after submitting the form there are two(!) records inserted so it looks like the script...
1
2633
by: ansc1 | last post by:
Hello, I'm new to using php coding. I need help with the following: 1. There is a submit button on the form and is saves information to my database. After clicking on "Save Measurement" it redirects me to another page in my site. What I would like to do is change what page directs it to. Currently the submit button redirects me to page...
26
25593
by: webrod | last post by:
Hi, I have some php pages with a lot of HTML code. I am looking for a HTML validator tool (like TIDY). TIDY is not good enough with PHP tags (it removes a lot of php code). Do you have any idea? Thanks you very much
1
5743
by: Kesavan | last post by:
I install apache2 in /usr/local/apache2 and install php5 by ./configure --with-apxs2=/usr/local/apache2/bin/ apxs PHP is successfully installed in my system. But now my .php files inside /usr/local/apache2/htdocs doesn't get phrased. When I run suse-10-2:/home/kesavan # php info.php
0
7177
by: Tarik Monem | last post by:
I have been working on an all AJAX/DOM web site which is set to go live today and I thought I'd share my discoveries with all of you whom have helped me when I have encountered different issues along the way. First, deep linking is not something that a completely AJAX web site should be able to do by it's very nature of everything being on one...
0
2741
by: Benjamin Grieshaber | last post by:
Hi, I´m on SuSE 9.3 with xmlrpc-c and xmlrpc-c-devel installed (ver. 0.9.10) I tried to compile php with xmlrpc support and got the following errors: ext/xmlrpc/.libs/xmlrpc-epi-php.o(.text+0x359): In function `set_zval_xmlrpc_type': /php-5.2.5/ext/xmlrpc/xmlrpc-epi-php.c:1313: undefined reference to...
0
1339
by: Patriot89 | last post by:
I have a quick question in reference to php file extenstions... I have code for example like this... This is all located on this site www.ixalliance.com/BHS/Default (This is my nav.php file) <div class="navstyle" id="navmenu"> <ul> <li><a href="index.php">Home</a></li> <li><a href="administration/admin.php"...
0
7850
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7779
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7874
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8150
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6524
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3786
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3801
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1391
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1114
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.