473,379 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Comparing Dates

i need to send mail 1 month before expirydate stored in database to a client..till now i can just compare the dates by converting them using strtotime.is there anyways to find out many days are left till expirydate.
Jul 4 '08 #1
6 1138
Hi bips

here it is what I understood you want to do

Expand|Select|Wrap|Line Numbers
  1. //considering this date is being fetch from db and was stored in this format
  2. $date = "2008-07-15 22:15:58"; 
  3.  
  4. $date1 = substr($date, 0, 11); 
  5.  
  6. $date2 = date("Y-m-d"); // current date
  7.  
  8. $difference = abs(strtotime($date2) - strtotime($date1));
  9.  
  10. $days = round(((($difference/60)/60)/24), 0); //remaining days
  11.  
$date is the expiry date, $date2 is the current date and $days is the total no. of days left till the expiry date.
Jul 4 '08 #2
hsriat
1,654 Expert 1GB
How are you doing that, if you can show some code?
Jul 4 '08 #3
How are you doing that, if you can show some code?
thank you i finally made the code worked

Expand|Select|Wrap|Line Numbers
  1. $chexpiraton = strtotime($expiration);
  2.  
  3.      $today = date("Y-m-d");
  4.      $chtoday = strtotime($today);
  5.     $diff = $chexpiraton - $chtoday;
  6.     $noday = $diff / (24*60*60);
  7.  
$expiration contains date from the database;
Jul 4 '08 #4
hsriat
1,654 Expert 1GB
thank you i finally made the code worked

Expand|Select|Wrap|Line Numbers
  1. $chexpiraton = strtotime($expiration);
  2.  
  3.      $today = date("Y-m-d");
  4.      $chtoday = strtotime($today);
  5.     $diff = $chexpiraton - $chtoday;
  6.     $noday = $diff / (24*60*60);
  7.  
$expiration contains date from the database;
What format is $expiration?.. If its simple UNIX time stamp, then subtract 30*24*60*60 from it and compare it with 'sec' index of gettimeofday array.
Jul 4 '08 #5
r035198x
13,262 8TB
What format is $expiration?.. If its simple UNIX time stamp, then subtract 30*24*60*60 from it and compare it with 'sec' index of gettimeofday array.
See his post above. He's already got it to work correctly.
Jul 4 '08 #6
hsriat
1,654 Expert 1GB
See his post above. He's already got it to work correctly.
Oh, thanks for that :)
Jul 4 '08 #7

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

Similar topics

4
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....
2
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...
2
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...
2
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...
2
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
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...
12
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...
4
by: cheryl | last post by:
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...
2
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. ...
4
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 =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.