Re: [PHP] Date Question
Hi How about doing this in the query string you send to mysql: DATE_FORMAT(fieldname, '%d %m %y') this way you wont have to mess around with the array stuff. for more info look here http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html Regards Pure Web Solution http://www.purewebsolution.co.uk PHP, MYSQL, Web Design Web Services Tom Chubb [EMAIL PROTECTED] wrote: Please can you help me. I've created a page where problems are posted into a database and I am using the datetime format in MySQL and trying to find the best way to display it in the 17/03/06 format. I've found a way of doing it (so you don't think I haven't googled, RTFM) but don't think it's the best way. Any help would be appreciated. (Current Code:) ?php $datestr = $row_rsSnags['date']; $arr1 = str_split($datestr, 2); echo $arr1 [2]; echo /; echo $arr1 [1]; echo /; echo $arr1 [0]; // echo $row_rsSnags['date']; ? Pure Web Solution http://www.purewebsolution.co.uk PHP, MYSQL, Web Design Web Services -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Question
on the fly: use date_format function in select statement, format should be a string like %d%m%y not sure about it check on manual. hth adriano 2006/3/17, Tom Chubb [EMAIL PROTECTED]: Please can you help me. I've created a page where problems are posted into a database and I am using the datetime format in MySQL and trying to find the best way to display it in the 17/03/06 format. I've found a way of doing it (so you don't think I haven't googled, RTFM) but don't think it's the best way. Any help would be appreciated. (Current Code:) ?php $datestr = $row_rsSnags['date']; $arr1 = str_split($datestr, 2); echo $arr1 [2]; echo /; echo $arr1 [1]; echo /; echo $arr1 [0]; // echo $row_rsSnags['date']; ?
Re: [PHP] Date question
If you are only avail with date-information then too you can use existing DATETIME field as following query.. INSERT INTO `test` (`testingdate` ) VALUES ( '2006-06-06'); it will take care of itself. Second way is you can change DATETIME field to VARCHAR (if you're not going to use those dates in date related calculations and MySQL functions etc.) Both ways it would work fine. William Stokes wrote: Hello, I have a datetime column in MySQL DB. How can I match to that column from php code if I only have the date information available. 2006-02-24 12:00:00 against2006-02-24 This might be more SQL question sorry about that. Thanks -Will -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date question
William Stokes wrote: Hello, I have a datetime column in MySQL DB. How can I match to that column from php code if I only have the date information available. 2006-02-24 12:00:00 against2006-02-24 This might be more SQL question sorry about that. Thanks -Will use date_format(%Y-%m-%d,'date_column') in the sql http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html -- Sumeet Shroff http://www.prateeksha.com Web Design and Ecommerce Development, Mumbai India -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date question
I have a datetime column in MySQL DB. How can I match to that column from php code if I only have the date information available. 2006-02-24 12:00:00 against2006-02-24 This might be more SQL question sorry about that. use date_format(%Y-%m-%d,'date_column') in the sql http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html The above is likely one of the more elegant solutions. But if you wanted to do this completely in PHP, you could do something like: pseudocode $phpDate = '2006-02-24'; $rowData = mysql_fetch_assoc( $yourQuery ); if( date( 'Y-m-d', strtotime( $rowData['MySQLDate'] )) == $phpDate )) { echo 'Dates match!'; } /pseudocode thnx, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] date question
Martin Cameron wrote: $ndays=14; function get_next_dates($ndays) { $today=date(m-d-Y,mktime(0,0,0,date(m),date(d),date(Y))); $forward_date=date(m-d-Y,mktime(0,0,0,date(m),date(d)+$few_days,date(Y))); print h1$today === $few_days === $forward_date/h1; for($i=0;$i$ndays;$i++) { $new_days_array[]=date(m-d-Y,mktime(0,0,0,date(m),date(d)+$i,date(Y))); } return($new_days_array); } What's the question? -- By-Tor.com It's all about the Rush http://www.by-tor.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] date question
Beautiful, many thanks Ahbaid. Martin Cameron wrote: $ndays=14; function get_next_dates($ndays) { $today=date(m-d-Y,mktime(0,0,0,date(m),date(d),date(Y))); $forward_date=date(m-d-Y,mktime(0,0,0,date(m),date(d)+$few_days,date(Y))); print h1$today === $few_days === $forward_date/h1; for($i=0;$i$ndays;$i++) { $new_days_array[]=date(m-d-Y,mktime(0,0,0,date(m),date(d)+$i,date(Y))); } return($new_days_array); } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] date question
quote Hello all, I would like to create a php function as follows: function get_next_dates($ndays) { /* 1. get the current date 2. create an array say $results 3. Store the dates for the next $ndays in $results */ return $results } So in my main program I can include the file with the function and use it as follows: ?php $next_4_dates = get_next_dates(4); ? $next_4_days[0] - 11/20 $next_4_days[1] - 11/21 $next_4_days[2] - 11/22 $next_4_days[3] - 11/23 if today was 11/19 Is there an easy way to do this? Can I somehow use something like getdate+7 say to get 7 days ahead? many thanks, Ahbaid /quote Try www.php.net/date -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DATE Question
--- Shaun [EMAIL PROTECTED] wrote: is there a function in PHP that will work out the amount of time(hours) beween two different dates / times? You can just subtract the timestamps the find the number of seconds between any two times. PHP has a rich set of functions to help you generate timestamps if you only have a text representation (05 Oct 2003) as well as functions to help you format dates. See here for more: http://www.php.net/manual/en/ref.datetime.php One of the first user comments looks to be a function that combines a few of these other functions together to do something like you are wanting. Hope that helps. Chris = My Blog http://shiflett.org/ HTTP Developer's Handbook http://httphandbook.org/ RAMP Training Courses http://www.nyphp.org/ramp -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date question
of course ;) but i couldn't find a reference to this particular problem... Jay Blanchard [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Have you checked the date functions at http://www.php.net ? -Original Message- From: Shaun [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 6:39 AM To: [EMAIL PROTECTED] Subject: [PHP] Date question Hi, For a given date, how can i find out the date of the day of the begining of that week? Thanks for your help -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date question
On Thu, 29 May 2003 15:40:00 +0100, Shaun wrote: of course ;) but i couldn't find a reference to this particular problem... I don't think you are going to find a standard PHP function to do this. You are going to have to do something like this (I haven't tried it but I think it will do what you want): // Get a starting time $d = strtotime( 12/31/2003 ); // Get the date of the Sunday on/or before that date $s = strtotime( - . date(w, $d) . days, $d ); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Date question
-Original Message- From: Shaun [mailto:[EMAIL PROTECTED] Sent: 29 May 2003 15:40 of course ;) but i couldn't find a reference to this particular problem... Jay Blanchard [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Have you checked the date functions at http://www.php.net ? -Original Message- From: Shaun [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 6:39 AM To: [EMAIL PROTECTED] Subject: [PHP] Date question Hi, For a given date, how can i find out the date of the day of the begining of that week? Have you tried searching the list archives? I'm pretty sure I answered this one with a strtotime() solution not that long ago, but it wasn't the most intuitively obvious way to do it. If you can't find that post, let me know and I'll see if I can dig it out of my Outbox archive. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date question
On Thursday 29 May 2003 22:40, Shaun wrote: of course ;) Try: $start_date_ts = time(); if ('Mon' != date('D', $start_date_ts)) { $start_date_ts = strtotime(last monday); } $start_date= strftime(%Y-%m-%d, $start_date_ts); echo $start_date; Season to taste. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-general -- -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Date question
Have you checked the date functions at http://www.php.net ? -Original Message- From: Shaun [mailto:[EMAIL PROTECTED] Sent: Thursday, May 29, 2003 6:39 AM To: [EMAIL PROTECTED] Subject: [PHP] Date question Hi, For a given date, how can i find out the date of the day of the begining of that week? Thanks for your help -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] date question
- Original Message - From: Charles Kline [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, March 19, 2003 2:17 PM Subject: [PHP] date question Hi all, I have a form where users will be adding publication dates for uploaded files. I want to store the date in mySQL as date('U') format. If the date is entered as mm/dd/ - will the date function know this or is there some way of 'telling' php how the date to be converted is formatted, if you all get what I am saying... Thanks Charles Many people prefer to do their date conversions in the SQL query. But if you have to do it in PHP then you can use the strtotime() function to convert that date into a timestamp then store it in mySQL. You shouldn't have to do anything special with the string.. strtotime() will convert any standard recognized date format. http://www.php.net/manual/en/function.strtotime.php HTH, Kevin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Date Question.
On 05-Mar-2003 Sebastian wrote: I have a date field in mysql in this format: Y-m-d H:i:s I would like to echo Today if the date is today, can someone offer some help? Thanks. SELECT IF(TO_DAYS(datefld)=TO_DAYS(current_date),'Today',LEFT(datefld,10)) as datefld, ... Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Date question
I have used strtotime() function in the past, and done this: if($time = strtotime('24 hours ago')) { $new = new!; } with it being in UNIX time stamp .. But now I have a different client where the time stamp in mysql is formatted like: 2002-08-29 10:53:09 what function would I use in this case, date() ? If so, how would I do the same exact thing? SELECT column - INTERVAL 24 HOUR FROM your_table WHERE ... ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date question
sorry, I do not see how that will work. I need a function that will know if 2002-08-29 10:53:09 was 24 hours ago, and if true, new will appear. warm regards, Sebastian - [BBR] Gaming Clan http://www.broadbandreports.com - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: 'Sebastian' [EMAIL PROTECTED]; 'php list' [EMAIL PROTECTED] Sent: Sunday, March 02, 2003 12:40 AM Subject: RE: [PHP] Date question | | SELECT column - INTERVAL 24 HOUR FROM your_table WHERE ... | | ---John W. Holmes... - Original Message - From: John W. Holmes [EMAIL PROTECTED] To: 'Sebastian' [EMAIL PROTECTED]; 'php list' [EMAIL PROTECTED] Sent: Sunday, March 02, 2003 12:40 AM Subject: RE: [PHP] Date question | I have used strtotime() function in the past, and done this: | | if($time = strtotime('24 hours ago')) { | $new = new!; | } | | with it being in UNIX time stamp .. But now I have a different client | where | the time stamp in mysql is formatted like: | 2002-08-29 10:53:09 | | what function would I use in this case, date() ? If so, how would I do | the | same exact thing? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date question
Hi, Sunday, March 2, 2003, 3:39:37 PM, you wrote: S Greetings all. S I have used strtotime() function in the past, and done this: if($time = strtotime('24 hours ago')) { S $new = new!; S } S with it being in UNIX time stamp .. But now I have a different client where S the time stamp in mysql is formatted like: S 2002-08-29 10:53:09 S what function would I use in this case, date() ? If so, how would I do the S same exact thing? S thanks. S warm regards, S Sebastian - [BBR] Gaming Clan S http://www.broadbandreports.com you can do if(strtotime($mysq_timestamp) = strtotime('24 hours ago')) { strtotime can take a mysql timestamp directly I think -- regards, Tom -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] date question
Not sure why you need the 5 days in advance bit, but this might give you the tools to work it all out. I prefer to work with dates in unix timestamp format (seconds). To get now, use time() To get next month, there's a kewl function called strtotime(), which converts english phrases into timestamps... eg strtotime(+1 month) might do the job, or next month... experiment, use the manual, etc etc To get now - 5 days either use strtotime(-5 days) or ? $nowMinus5days = time() - 432000; // 432000 = 5x24x60x60 $nowMinus5days = date('d/m/y', $nowMinus5days); ? Hope this helps, Justin on 29/09/02 3:04 PM, Jonas Geiregat ([EMAIL PROTECTED]) wrote: I have a date ex 24/08/02 and I need to see if that date is the same date as it is today (only one month later) but 5day's in advanced = that would be 24/09/02 so if(date == date now - 5) {true} else{false} how can I do this right ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] date question
Hi Meltem, The PHP manual is at http://www.php.net/manual/en (mirror sites as well). -Original Message- From: Meltem Demirkus [mailto:[EMAIL PROTECTED]] Sent: Monday, September 09, 2002 1:30 PM To: [EMAIL PROTECTED] Subject: [PHP] date question Hi, Is there any function which returns the day , month or year of a date ? thanks meltem -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] date Question
On Monday 20 May 2002 23:01, Randy Johnson wrote: Is their a way to retrieve the previous month using/altering the code below: // get the current timestamp into an array $timestamp = time(); $date_time_array = getdate($timestamp); $month = $date_time_array[mon]; $day = $date_time_array[mday]; $year = $date_time_array[year]; $tmonth= $date_time_array[month]; outputs 5202002 May i need it to output 4/20/2002 April strtotime(); -- Jason Wong - Gremlins Associates - www.gremlins.com.hk Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * /* Speaking of purchasing a dog, never buy a watchdog that's on sale. After all, everyone knows a bargain dog never bites! */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] date Question
Hi, If you want last month from the *CURRENT* date + time, then look at something like strtotime('last month'), which may help, generating a time stamp of the same day, time, etc in the previous month. To format a different time stamp into what you want, consider the date() function in the manual... for starters, it's quicker for the code you have below: NOTE: untested code :) ? $timestamp = time(); $formated_date = date('m/d/Y', $timestamp); echo $formated_date; // echos what you already had ? however, since we want to have one less month: ? $timestamp = time(); $month = date('m', $timestamp); $day = date('d', $timestamp); $year = date('Y', $timestamp); // subtract 1 from $month, unless it's // value is 1, in which case it should be // 12, and the year dropped by 1 as well if($month == 1) { $month = 12; $year = $year - 1; } else { $month = $month - 1; } $formatted_date = {$month}/{$day}/{$year}; echo $formatted_date; ? I have no idea why you want to output April in addition to 4, but you can take your $formatted_date, feed it into strtotime(), which gives you the new timestamp. From there, you can get a word month out of the date() function, which gives you the text April: ? //.. continued from above code $new_timestamp = strtotime($formatted_date); $month_t = date('F', $new_timestamp); echo $month_t; ? There are prolly better ways to do this, but you can see, if you think about it, and read the manual (just two pages!), you'll get what you want. Justin French on 21/05/02 1:01 AM, Randy Johnson ([EMAIL PROTECTED]) wrote: Is their a way to retrieve the previous month using/altering the code below: // get the current timestamp into an array $timestamp = time(); $date_time_array = getdate($timestamp); $month = $date_time_array[mon]; $day = $date_time_array[mday]; $year = $date_time_array[year]; $tmonth= $date_time_array[month]; outputs 5202002 May i need it to output 4/20/2002 April Thanks Randy -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Date Question
If you put the date in MMDD format you can compare the numbers. http://www.php.net/manual/en/function.date.php Jeff Oien Hi, Since there is no Date type in php, is there a way to compare dates? Something like: if ((3/8/2001) (3/9/2001)){ // Date is newer } Thanks, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Date Question
You might try converting these dates to Unix time and then compare the numbers as integers. Let's see, here is a function that converts the data from a MySQL date field to a Unix timestamp... function mysql_to_epoch ($datestr) { list($year,$month,$day,$hour,$minute,$second) = split("([^0-9])",$datestr); return date("U",mktime($hour,$minute,$second,$month,$day,$year)); } And here is where I use it to calculate the age of the item in the database. $epochTime = mysql_to_epoch($messageCreated); $currentEpochTime = time(); $ageInSeconds = $currentEpochTime - $epochTime; I hope this provides a clue for your application. John -Original Message- From: Chris [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 08, 2001 12:12 PM To: php Subject: [PHP] Date Question Hi, Since there is no Date type in php, is there a way to compare dates? Something like: if ((3/8/2001) (3/9/2001)){ // Date is newer } Thanks, Chris -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Date Question
Ok, I understand that the epoch is a point in time that's static, but what exactly is the epoch? I've heard it mentioned a lot on the list, but I have no idea what it really is. :) Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Date Question
If it is on a Unix box, it most likely is the Unix time value; It is the number of seconds since the UNIX Epoch which I believe starts at 0 seconds in January 1970. I am not quite sure about that date, but it is close. It also reveals the problem if you are dealing with dates before 1970 and after 2^32 seconds after that. Again, this specifics above may not be totally accurate, but are close enough to describe the point. John -Original Message- From: Jason Jacobs [mailto:[EMAIL PROTECTED]] Sent: Thursday, March 08, 2001 12:22 PM To: [EMAIL PROTECTED] Subject: Re: [PHP] Date Question Ok, I understand that the epoch is a point in time that's static, but what exactly is the epoch? I've heard it mentioned a lot on the list, but I have no idea what it really is. :) Jason -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] date question
Which database? Fang Li [[EMAIL PROTECTED]] wrote: There is a LiveDate (-MM-DD) field in my table. 1. I want data from last 5 days up to now, and its order should be from latest; 2. I want data for next month. Any help would be appreciated. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]