Date Calculations?
I'm having trouble with a simple date calculation. Basically I have to time stamps, $todays_date and $date_joined. I want to find out how long a member has been registered on my forum in days months years atm I'm taking $date_joined off $todays_date but its giving me an actual date which is 1971-06-05 but I actually want something like 30 days or 2 months 3 days not the actual date if that makes any sense.
Heres my code:
$todays_date=time();
$date_joined=$member_row['user_joined'];
$join_time=$todays_date-$date_joined;
echo "Join time: ". date('Y-m-d', $join_time)."
";
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Calculations With Date
i've got 2 date values, both in the format yyyy-mm-dd, has anyone any ideas how to perform a calculation, so that I can take one date away from the other and be left with the days/difference between
Date Calculations
I'm doin the old calculate persons age from database routine. Had a good search around and found out about Unix timestamps. Been looking those up and trying to figure out how to use them properly. My dates are of the d-m-Y format.. I.E.. today is 11-02-2007 I did it this way so i can use date("d-m-Y") to grab todays date elsewhere in the site and it's all the same format. Problem is that I can't quite grasp timestamps. I tired something like this.. $dobts = strtotime($dateofbirth); $todaysdate = date("d-m-Y"); $todaysdatets = strtotime($todaysdate); $agets = $todaysdatets - $dobts; $age = date("d-m-Y", $agets); Didn't work of course but it thought that was the point of these timestamps?
PHP And MySQL Date Calculations
I have a date type in mySQL, and I want PHP to run a select where it grabs todays date, checks against my database, and returns all values that are new within 30 days. I cant seem to find any help anywhere. Here's what I got so far for it: $current = getdate(); $this_month = $current["mon"]; that will at least get me the month, the problem is testing it against the date type in the select statement.
Date Calculations Advice
I am getting the date like this $date = strtotime(date()); ok, there you have it, a Unix time stamp of the time, date, and everything else. From here, is this the best way to do calculations. Like if I wanted to tell when 48 hours had passed from this date, how do I go about doing that. I know for example if you wanted to add a day, you check on how many "number's" here are in a day and put + that number onto the strength. Can someone tell me some stuff about this, so I am more familiar with dates, before I start all of these calculations.
Simple Date Calculations
What I am trying to do is show the difference between two dates - one will be "today" and the other will be the date on which an entry was made into the database for that particular user. I tried doing $difference = $today - $entrydate but this did not give me any kind of figure. Both dates are stored in the format of, for example, 21 Feb 07, 11:22am Would the time cause problems?
Calculations
i want it to calculate a value that is in the db if the db has the value 6 pound(s) (i have a submit button) and the users enters in the input box a value for more pounds then how do i make it calculate in fractions or even divisions.. cause see this is what i have. PHP Code:
Calculations
<?php echo 04 - 1; ?> that echo's 3 I need it to echo 03, is there an easy way to do this?
Binary Calculations
I'm not sure if PHP can do this but I have a client that would like to provide unlock codes for a CD they have. They have given me a document that describes the Binary calculation that is required to calculate the unlock code based on the CD serial number. They also refer to EX/OR or exclusive or. The also refer to hex data which I'm assuming is hexidecimal which I'm pretty sure PHP can deal with. I'm interested in finding out if PHP can work with binary, ex/or and hexidecimal data. If not any other possible solution, ie. library or other language such as Perl. I would also appreciate any links to additional info.
Auto Calculations
I've seen on a few sites that in a shopping enviroment if you choose a price from a drop down and then maybe a delivery ares, the actual price shown for the product is updated instantly without page refresh.
Doing Time Calculations...
For a project I am working on right now I need to be able to calculate the time difference between to given times. (For example...The difference between 11:30 am and 1:45pm being 2:15) Right now the input is setup as 2 text boxes, 2 dropdowns, and 2 radio groups. The text boxes get the hour entered into them, the drop downs holdd a list contaning 00, 15, 30, and 45 (the minutes) and the radio groups being am or pm. Is it possible to use that configuration and somehow get the time difference? or do I need to change the input? The goal is to be able to enter the two values and immediately see a calculated difference in a third textbox on the page. I'm thinking something like.... User enters hour in first text box(textHFrom) - 11 User selects minue value from second dropdown(cboMFrom) - 30 User selects am/pm from radio group(radioF) - am User enters hour in second text box(textHTo) - 1 User selects minue value from second dropdown(cboMTo) - 45 User selects am/pm from radio group(radioT) - pm onChange of second RadioGroup time is calculated and result in inserted into third text box(textHours) - 2:15 I'm not sure if/how to bet do this.
Time Calculations
i have a field in mysql which contains a timestamp: 2007-07-25 22:52:14 i was going to add a new variable but adding 1 hour to it so it would read: 2007-07-25 23:52:14 im not sure how to format the date to read add 1 hour to the date stamp.
Calculations Within A Field
i have a field which is float, it stored the price of an item, i need to create another field called points which times the price by 0.1 and stores that value. how would i do this? can the sql database do it itself or would i need to create a function in php that will convert it then store the points?
How To Do Calculations Using JOIN Statement?
I have three tables -: Customer Table AccountID field Name field Invoice Table InvoiceID field invoice_date field CustomerID field Amount field Payment InvoiceID field Payment_Amount field payment_date field PHP Code:
Check Date From Input Must Greater Or Equal Today Date?
I have 3 select box. Code: <select name="day"> <option value="1">1</option> <option value="2">2</option> ....... <option value="31">31</option> </select> <select name="month"> <option value="01"> Jan </option> <option value="02"> Feb </option> ..... </select> <select name="year"> <option value="2002">2002 </option> <option value="2003">2003</option> </select> When I select and click submit in form. I will have 3 variable : $day, $month and $year How can I check the day that I choose in form must equal or greater than today date? If it less than today date. I must print error message to user.
Date Is Not Being Pulled From MYSQL Database, Instead Current Date Is Displayed!
I am having trouble pulling a date from a database using PHP at the <a href="http://www.mytuneslive.com/ameshkin69/"> following page.</a> Here is the code. As you can see, it is just making the date the current time. The values in the database are UNIX timestamp, and the DATE() function is used to convert from UNIX to readable date. Can <td width="55%" align="left" valign="top"><?php $row_comment['timestamp'] = date("n d Y g:i A");.....
Read Today's Date Print Tomorrow's Date
I've got a small script that writes a random number and the date to a text file. Then the script opens this text file and if date = date from this text file something must happen. If something happened this script must open this text file again and replace it with a new random number and tomorrow's date. <?php $date = date("d-m-Y"); mt_srand((double)microtime()*10000000000); $num=mt_rand(0, 20); if ($num == $num && $date == "$tomorrowdate") { echo"$num -- $date";} else echo " ";?> So if the script gets activated on the 05-05-2003 it must write tomorrow's date into the text file (06-05-2003). How will I get tomorrow's date today?
Help: Date Function Not Returning Correct Date & Time
I have just notices that the date() function is not returning the correct date/time on my "server". I am running apache2 on my winxp pro laptop. My system clock is set to the correct date, time and timezone, get the results returned by date() are 11 hours behind.
PHP Date Question: How To Determine The Date Each Of The Past 3 Sundays
How can I determine what the date was (in YYYY-MM-DD format) last Sunday, and the Sunday before that? For example: Today is Thursday, August 18, 2004 (2004-08-18). I would like to have the following variables: $this_past_sunday = 2004-08-14 $two_sundays_ago = 2004-08-07 $three_sundays_ago = 2004-07-31 etc. etc.
Save Date To Table Field Date Type
I have a calendar picker on a form that fills a text box with XX/XX/XXXX date format. If I run a insert statement the date field in the database shows 0000-00-00. If i change the field type to varchar the correct format displays. What is the correct way to save a date to a mysql database? Furthermore to query on the date how about a select * from db_name where servicedate >= $startdate and servicedate >= $enddate I supose this will not work Any pointers?
Date Dropdown From Mysql Date Entries
For the PHP gurus out there, here is what I want to do: create a dropdown list of available dates from a mysql database date entries. But the dropdown/s should have 3 separate fields in month, day and year which in effect shows only those months, days and years that have corresponding entries from the database. Planning to use this in the archive section of an online news publication so people can select issues to view via dropdown list that have corresponding entries only.
Start Date - End Date = Number Of Days
I have a starting date for var 1 and today’s date for var 2. I need to calculate how many days are between those two dates. 02/24/03(today) - 01/14/2002(start date) = number of days. In theory this is easy but there are many instances were I could get an inaccurate answer. For example one consideration is that some months have 30 days others have 31. exc. My question is, is there an easier way to solve this problem other than using endless if statments to error handle all possible instances? Does PHP4 have any built in functions that could calculate this formula correctly?
UNIX Mktime To MySQL Date Or Date
A form that sends a starting date and an ending date. I have figured out how to tell the difference between the two and even rip the difference into an array because I need to compare the individual dates against a mySQL database to pull results from a particular date in a series. This is no problem. My problem is that teh mySQL database uses DATE as a field definition and this can not be changed. I managed to pull the date differences using some cleaver mktime stuff but no I do not know how to get this 1072242000 into this 2003-12-24... Is there a function that reverses the mktime result into a usable date format? I would take anything at this point and I can explode and then array it to get what I want - but there has to be something. Code:
Formatting Date From MYSQL Date Field
i've got a date field in my table, but the default format is YYYY-MM-DD... is there any way i can pull the date out of the database and format it differently... like DD.MM.YYYY or like April 13, 2003?
Counting Days From $date To Current Date
how to count the time between two variable dates? Such as someone inputting 6/8/1991 in a form and it comparing that to todays date... then getting the number of seconds elapsed... I know I have to use the mktime() function to get the seconds.. but not quite sure how.
Date() Gives Me Yesterday's Date And Not Today's - Why?
$result[$i]->record_entered contains the current date as set up by MySQL (entered as "now()"). I verified that in the database the date is "now()", which in this case will be "2/9/2006". However, when viewing the page using the display: Code: ( php )
Begin Date And End Date, But No Weekends!
I am making a system to plan my work days. If i begin on a project on 01-10-2007, and the project is 100 hour and i work 10 hours a day, it will cost 10 days for me too work. The answer is simple, project is done @ 10-10-2007, but i dont work in the weekend. So it must be 12-10-2007, i got the following script;, but it aint working right. Because when the begin date and end date is more then 2 weeks, and more than 2 weekends, it doenst count the weekends good. Can someone help me, or is there somebody with a better solution? I am working two days on it, but i cant get it right <?php $begin_date = strtotime( date( '2007-10-01' ) ); $hours = 100; $workdays = 10; $total_days = $hours / $workdays; $total_days *= (60 * 60 * 24); $weekend = $total_days / 7 * 2; $enddate = $begin_date + $total_days + $weekend; if( date('D', $enddate ) == 'Sat' ) { echo 'End date <b>' . date('d-m-Y', $enddate + (2*86400)) . '</b> 2 days<br /><br />'; } elseif( date('D', $enddate ) == 'Sun' ) { echo 'End date <b>' . date('d-m-Y', $enddate + (1*86400)) . '</b> 1 day<br /><br />'; } else { echo 'End date <b>' . date('d-m-Y', $enddate) . '</b><br /><br />'; } ?>
Date Conversions ( Date, Mktime )
I have a date in three pieces dd mm yyyy. I'm just wondering the best way to convert this for inserting into a DATETIME field and then back again when displaying it. I have tried date, strtotime mktime but it keeps inserting a blank date. i.e. 00:00:00 00:00... I've been looking through the php manual but I can't seem to get this working. Also would I be better off using the UNIX_TIMESTAMP function?
Check Date Is Not Before Current Date
I need to validate a date entered to make sure it isnt before the current date. I have managed to this in Javascript but not sure how to do this in PHP when the value is submitted.
Date Time Not Accurate For Date();
echo "date=".date('Y-m-d h:i:s'); date=2007-11-15 15:48:14 the clock is the accurate at here..showing only 3pm ..while now my pc showing 11.51pm(localtime)
Put Today's Date Into A MySQL "date" Formated Field
My MySQL table has a field that is set as type "date." I need to get today's date, and insert it into that field. The default for that MySQL field is 2006-00-00. I know about the date() function. I have tried date("Y-m-d") and date("U"), neither worked. The date field was just filed with all zeros. Can anybody point me in the right direction?
Date And System Date
I am currently looking for a way to compare the current system time date to a date that is in my database. PHP Code:
Change $row['date'] To $date
When writing the code to display the mysql_fetch_assoc results I'd like to remove the $row[''] portion and just leave it as a variable like this: $date, $numid, $text and on and on. For the life of me I can't remember how to do it... even though I know I looked at this last week sometime.
Start Date End Date
I am creating a simple auction site. There will be a start date which I think will be a timestamp and an end date. How can I do code the end date so that it is $days until it closes? I am not asking for code (although that may be helpful) I am asking for an explanation.
Date From And Date To Fields
I have a table which contains special offers starting from a certain date and ending at another date. Therefore would I just do $date = date("Y-m-d H:i:s "); SELECT * from Tablename WHERE start_date <= '$date' && end_date >= '$date' Is this correct?
Date() Help
Here's my question. I made an litle calendar that displays the days of the month. if in a certain day i have something booked it displays a link to the day information.
Php Date
I get the todays date- yesterdays date and tomorrows date, like so: $yesterday = date ("Y-m-d", mktime (0,0,0,date("m"),(date("d")-1),date("Y"))); $tomorrow = date ("Y-m-d", mktime (0,0,0,date("m"),(date("d")+1),date("Y"))); $actualdate = date("Y-m-d"); Which returns the date in the format "200-11-13" But I need to add 13 hours to all three - how owuld I do this?
Date
i still have the problem with daylight saving last Sun of March will increase 1 hour of the normal time and first Sun of Oct will set back to normal time: I try date("I") and it's doesn't work.
Php Date Help
I am trying to show how old a post in my mysql db is, the date field is using the mysql date/time stamp [2007-04-24 17:45:18] and i need to compare compare this date with the one from NOW(). Also how to convert the result so that it returns in the format like [1 Days 14 hrs]?
After Certain Date Do This....
I am creating an internal site for work. Basically we will be adding names and info to a database that have to have certain things done before a certain date. Each date is different. I need a little help with a php script that will detect the date and change the font colour to red if the date is 5 days away or has passed completely. I would like to have an email sent to a certain person when it is 5 days before, then an email sent to multiple people if the date arrives and passes ...
Date()
I have listed the code I am using to try and add a date to an email. I cannot seem to find the problem, maybe someone with more experience can. When I check the email the php sends me, it adds the ' . date() . ' as regular text instead of adding the actual date, I cannot figure out whats wrong with the code:
Set Date?
Can you tell PHP to set the date on your machine? Windows 2000 Pro Apache 1.3 & PHP 4
Date()
If the server time is 13:00, how can i make it 6 hours back (Eastern time). I tried just subtracting 6 from the time, but that gives negative numbers sometimes.
Less Than Date
how do i find if the $Previous_FDate is < (less than ) the $from. below is how i am calculating difference between 2 dates. PHP Code:
Date Help
I am sending the variables $daystochange and $datetostart to a php page to process. The point is to move all of the rows in the table by the amount sent in $daystochange where the date is equal to or after $datetostart. Right now $daystochange is just a number like 3 or -22. The problem comes when the $daystochange exceeds the number of days in the acutal month instead of rolling over it keeps on adding to the day making a date like 2000-12-42. When this gets entered into the database it is invalid and spits out 0000-00-00. Here is the code:
|