473,698 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Comparing Dates

9 New Member
I am using the PHP.MYSQL and Apache server application in developing my website. I have problem in comparing dates. Website has room reservation, the user will check first the room availability. The user will input dates using the combo box like cboyear,cboday and cbomonth. What SQL statement or quey should I write to compare it to the database. The database has already have value in dates. I want to compare the input date to the database.... What is the query of this..


Please somebody help me....
Jan 20 '07 #1
4 2349
CMNetworx
4 New Member
Here is one way, it requires that your dates are entered in by the unixtime function

[php]
$unixtime = strtotime('now' );

mysql_select_db ("yay") or die(mysql_error ());
$query = "SELECT * FROM tablename WHERE this = '$that' AND expires_on >= '$unixtime'"; [/php]

expires_on is one of the column names so in yours it may be

[php]AND listed >= '$unixtime'"[/php]
Jan 20 '07 #2
CMNetworx
4 New Member
This wont let me edit since its past 5 min, so I will repost

Here is one way, it requires that your dates are entered in by the unixtime function, which they may already be, and they may be translated out of..

[php]
$nice_post = date('F d Y', $this);
//This will return the variable $this from unix time to a readable date

$unixtime = strtotime('now' );
//makes current time into unix time string

//Can also be used like
$time = strtotime("10 September 2000")

mysql_select_db ("yay") or die(mysql_error ());
$query = "SELECT * FROM tablename WHERE this = '$that' AND time >= '$unixtime'";

//of course other variations would be = < or >[/php]

expires_on is one of the column names so in yours it may be
Jan 20 '07 #3
cassbiz
202 New Member
Hi Cheryl,

I am working on a very similar project. Ronverdonk posted this earlier and here is a great query to check for date availability.

[php]
<?
$query = "(SELECT * FROM table WHERE date BETWEEN '$var_from' AND '$var_to'
OR date1 BETWEEN '$var_from' and '$var_to';)";
?>
[/php]
Jan 20 '07 #4
cassbiz
202 New Member
There is one more note that I found is that the arrival date must be plus 1 day when comparing to a room becoming available. Otherwise the room will say occupied when it is really available.
Jan 20 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2408
by: F | last post by:
Hi I have posted the question few days back about problem in inserting the dates in SQL server and thankful to them who replied. That was solved and this is a nice solution. http://www.aspfaq.com/show.asp?id=2023 Now I am facing another problem. I have to get data between two dates. That dates user has to provide and in
2
8592
by: Mike N. | last post by:
I am currently using a function to validate a form on the client side (see code below). At the end of the function, I would like it to also compare a startDate against an endDate to ensure that the endDate is greater than (comes after) the startDate. The date format I'm using is MM/DD/YYYY and it's writing to an MS SQL Server 2000 database table via ASP. THANKS!!! function ValidateForm() { //validate STATUS element
2
1834
by: Duppypog | last post by:
I'm trying to compare a date stored in a database with today's date using an If statement, but it's not returning true. Example, value in database is 11/5/2003 with today being 11/6/2003. Can someone spot the problem? Thanks, Lynnette Here's the code: sSQL = "Select PWExpire FROM tblUsers where strUserName = '" & stUser & "' AND strPassword = '" & hshPW & "'"
2
1587
by: Philip Townsend | last post by:
I am having difficulty with a simple routine as follows: public static bool VerifyExpirationDate(DateTime date) { if(date>=DateTime.Now)return true; else return false; } The problem is that when today's date is passed in, the method returns false. Any ideas? Thanks!
2
3338
by: Manny Chohan | last post by:
Hi, i have two datetime values in format 11/22/04 9:00 AM and 11/22/04 9:30 AM. How can i compare dates .net c# or if there is any other way such as Javascript. Thanks Manny
2
18329
by: ameshkin | last post by:
Hi GUys, Im trying to compare two dates in MYSQL. But its not treating the dates as numbers, but as strings. I try using strtotime but that did not work. Basically, if the last comment is newer than the last user login, then I need for a message to pop up and say New Comments. If not, then no new comments. The area of this code which is not working is at the bottom.
12
5557
by: colincolehour | last post by:
I am new to Python and am working on my first program. I am trying to compare a date I found on a website to todays date. The problem I have is the website only shows 3 letter month name and the date. Example: Jun 15 How would I go about comparing that to a different date? The purpose of my program is to load a webpage and see if the content on the front page is fresh or stale as in older than a few days. Any help in the right direction...
2
1981
by: dantebothermy | last post by:
Is there a simple way to subtract the time from a datetime field, so when I compare dates, I'm always comparing the dates at 12:00 am? I'd really prefer not to convert all my dates to strings. Thanks, Dante
4
2355
by: jupi13 | last post by:
i have this code..i don't know what where is the error in this one..it says data type mismatch..... Dim Mydate As Date Dim MydateString As String MydateString = "Text1.Text" Mydate = CDate(MydateString) ''it is highlighted in this line.. txtActCode = Mydate i don't know what's wrong with this one..
0
8683
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9170
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8901
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8871
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4371
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 the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2336
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.