Re: [PHP] Date formatting issue
On Tue, Aug 5, 2008 at 11:48 AM, Don Don <[EMAIL PROTECTED]> wrote: > Hi all, > > I've got dates in the following formats e.g. > > August 05, 2008, 10:14 am (e.g. today's date) > August 04, 2008, 7:08 am (e.g. yesterda's date) > August 03, 2008, 9:08 am (e.g. in the past) > > I am trying to format these dates do I can display them like this > > Today at 10:14 am (today) > Yesterday at 9:08 am (yesterday) > August 03, 9:08 am (if its not today or yesterday then display the month and > day and time only) If $month equals date("m") and $year equals date("Y") and $day equals date("d") - 1 then it's yesterday. If $month equals date("m") and $year equals date("Y") and $day equals date("d") then it's today. If $month equals date("m") and $year equals date("Y") and $day equals date("d") + 1 then it's tomorrow. Otherwise, echo date("F d, g:i a"); As Dan Joseph mentioned, read up on date()[1] and mktime()[2], and I'd also recommend strtotime()[3]. Moreover, take the logic above and code your PHP to match it. A simple if/elseif/else or case/switch block will do it for you. 1: http://php.net/date 2: http://php.net/mktime 3: http://php.net/strtotime -- More full-root dedicated server packages: Intel 2.4GHz/60GB/512MB/2TB $49.99/mo. Intel 3.06GHz/80GB/1GB/2TB $59.99/mo. Intel 2.4GHz/320/GB/1GB/3TB $74.99/mo. Dedicated servers, VPS, and hosting from $2.50/mo. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date formatting issue
On Tue, Aug 5, 2008 at 11:48 AM, Don Don <[EMAIL PROTECTED]> wrote: > Hi all, > > I've got dates in the following formats e.g. > > August 05, 2008, 10:14 am (e.g. today's date) > August 04, 2008, 7:08 am (e.g. yesterda's date) > August 03, 2008, 9:08 am (e.g. in the past) > > I am trying to format these dates do I can display them like this > > Today at 10:14 am (today) > Yesterday at 9:08 am (yesterday) > August 03, 9:08 am (if its not today or yesterday then display the month > and day and time only) > > Can anyone help with tips on how to achieve this ? > > Cheers > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Check out date() and mktime() -- http://www.php.net/date http://www.php.net/mktime Both of those should get you in the direction of formating dates. -- -Dan Joseph www.canishosting.com - Plans start @ $1.99/month. "Build a man a fire, and he will be warm for the rest of the day. Light a man on fire, and will be warm for the rest of his life."
Re: [PHP] date formatting
On Wed, August 29, 2007 4:12 pm, Mike Ryan wrote: > I would like to have my users input the date formate as mm-dd- > mysql > wants the data to come down as -mm-dd. > > The question I have is how do I convert from the mm-dd- to > -mm-dd so > that I can write it out to the database? You could tell MySQL to use the mm-dd- input format I think. Ask on a mysql list. In PHP: die() is probably a bit extreme for this, but it's a start. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Please vote for this great band: http://acl.mp3.com/feature/soundandjury/?band=COMPANY-OF-THIEVES Requires email confirmation. One vote per day per email limit. Obvious ballot-stuffing will be revoked. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] date formatting
Just have your input form get it in sections, then piece it all together when dumping it to MySQL This way you can transparent the code on the front to users, but have it in the right format in the backend. Mike Ryan <[EMAIL PROTECTED]> wrote: > I would like to have my users input the date formate as mm-dd- mysql > wants the data to come down as -mm-dd. > > The question I have is how do I convert from the mm-dd- to -mm-dd so > that I can write it out to the database? > > -- > 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 Formatting
thanks for all the replies. I was able to use the date_format() from MySQL. Clint - Original Message - From: "Rick Emery" <[EMAIL PROTECTED]> To: "Clint Tredway" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Friday, December 13, 2002 1:13 PM Subject: Re: [PHP] Date Formatting > MYSQL will do all the formatting that you need. Look up sect 6.3.4, "Date and Time > Functions" in mysql manual. Look at the DATE_FORMAT(date,format) command > > - Original Message - > From: "Clint Tredway" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Friday, December 13, 2002 11:55 AM > Subject: [PHP] Date Formatting > > > How can I format a date coming out of a MySQL? I know how to format today's date but not a > date coming out of MySQL. I have looked through the manual, but I must be blind because I > cannot figure it out. > > Thanks, > Clint > > > -- > 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 Formatting
MYSQL will do all the formatting that you need. Look up sect 6.3.4, "Date and Time Functions" in mysql manual. Look at the DATE_FORMAT(date,format) command - Original Message - From: "Clint Tredway" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, December 13, 2002 11:55 AM Subject: [PHP] Date Formatting How can I format a date coming out of a MySQL? I know how to format today's date but not a date coming out of MySQL. I have looked through the manual, but I must be blind because I cannot figure it out. Thanks, Clint -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Formatting
Use DATE_FORMAT() in your query, or UNIX_TIMESTAMP() to pull it out as a unix timestamp and use date() in PHP to format it. Chapter 6, Date and Time Functions in the MySQL Manual has the syntax for each of the MySQL functions. ---John Holmes... - Original Message - From: "Clint Tredway" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, December 13, 2002 12:55 PM Subject: [PHP] Date Formatting How can I format a date coming out of a MySQL? I know how to format today's date but not a date coming out of MySQL. I have looked through the manual, but I must be blind because I cannot figure it out. Thanks, Clint -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Formatting
Just a small question, but why not just do this through the SQL statement instead of using php? http://www.mysql.com/doc/en/Date_and_time_functions.html#IDX1295 [from the mysql manual] mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00', '%W %M %Y'); -> 'Saturday October 1997' mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00', '%H:%i:%s'); -> '22:23:00' mysql> SELECT DATE_FORMAT('1997-10-04 22:23:00', '%D %y %a %d %m %b %j'); -> '4th 97 Sat 04 10 Oct 277' - Original Message - From: "Clint Tredway" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, December 13, 2002 11:55 AM Subject: [PHP] Date Formatting How can I format a date coming out of a MySQL? I know how to format today's date but not a date coming out of MySQL. I have looked through the manual, but I must be blind because I cannot figure it out. Thanks, Clint -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date Formatting
Use this: function makedate($format, $indate) { $temp = explode("-", $indate); $fulldate = mktime(0, 0, 0, $temp[1], $temp[2], $temp[0]); $temp = date($format, $fulldate); return ($temp); } and call it with this: makedate("F d, Y", $row->datefield); where $row->datefield is the variable of the date field in your table. Peter At 11:55 AM 12/13/2002 -0600, you wrote: How can I format a date coming out of a MySQL? I know how to format today's date but not a date coming out of MySQL. I have looked through the manual, but I must be blind because I cannot figure it out. Thanks, Clint - - - - - - - - - - - - - - - - - - - - - Fourth Realm Solutions [EMAIL PROTECTED] http://www.fourthrealm.com Tel: 519-739-1652 - - - - - - - - - - - - - - - - - - - - - -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date formatting from a mySQL timestamp
> I have the following query : > for($i = 0; $i <=$num_results; $i++) > { > $row = mysql_fetch_object($result); > echo "\n" >."\n" You can save some typing if you just set the bgcolor in the , instead of each , FYI. Also, align defaults to "left", doesn't it? So you can probably leave that out, also. >."$row->id\n" >."$row->Nombre\n" >."$row->Apellido\n" >."$row->Direccion\n" >."$row->Ciudad\n" >."$row->Telefono\n" >."$row->Mail\n" >."$row->Pais\n" >."".date("r", > $row->date)."\n" > // My problem is it's getting the wrong date no matter what I do, every line > displays Jan 2038 !!! I think you're confused here. MySQL uses a different style timestamp than a Unix timestamp. Unix timestamps are the number of seconds since Jan 01, 1970. MySQL timestamps are in a MMDDHHMMSS format. If you've used a TIMESTAMP, DATE, or DATETIME column in MySQL, then you have a MySQL timestamp. The MySQL timestamp is not compatible with the PHP date() function, it is expecting a Unix timestamp. So...the solution is one of two things. You can use an INT column and store the unix timestamp into it. You can create the unix timstamp in PHP with time(), mktime(), or strtotime() (among others), and format it with the date() function. Or, you can continue to use a MySQL type timestamp and use the MySQL function DATE_FORMAT() to format the dates _in your query_. DATE_FORMAT() is the MySQL equivilent of PHP's date() function. Or, as a third option, you can use the MySQL UNIX_TIMESTAMP() function to create a Unix timestamp from the MySQL timestamp and return that to PHP. You can then use that in your date() function. Confusing, eh? If you have any questions, I can explain it further. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Date formatting
On Wed, Jul 10, 2002 at 12:25:08PM -0500, Rw wrote: > > "01-02-2003" > > Is there a handy function to convert that to other ways of expressing the > date such as: > > "01/02/03" $temp = preg_replace('/^(\d{2})-(\d{2})-(\d{2})(\d{2})$/', '\\1/\\2/\\4', $date); > "2003-01-02" $temp = preg_replace('/^(\d{2})-(\d{2})-(\d{4})$/', '\\3/\\1/\\2', $date); It's also a good idea to do a test to make sure the initial date is in the format you expect it to be: if ($temp == $date) { echo 'WAIT a second... Your initial date was bad.'; } --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Date formatting
To convert from user format to mysql I use: $training_date=$_POST["training_date"]; $training_date=str_replace("-", "/", $training_date);//strtotime doesnt seem to work right if it has 12-25-2002, but does if it has 12/25/2002 $training_date=strtotime($training_date); $training_date=date("Y-m-d",$training_date); To convert from mysql to user I do: $field_hire_date=$row_current_emps['field_hire_date']; $field_hire_date=strtotime($field_hire_date); $field_hire_date=date("m/d/Y" , $field_hire_date); -Original Message- From: Rw [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 11:25 AM To: [EMAIL PROTECTED] Subject: [PHP] Date formatting Had trouble getting this posed at the newsgroup - will try on the maillist here: I have a date field passed in a form like this: "01-02-2003" Is there a handy function to convert that to other ways of expressing the date such as: "01/02/03" OR "2003-01-02" I know the syntax of the date formatting expressions ... just not for the converting. Thanks! -- 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 formatting
Here, play with this. dtAuctionStart is a MySQL date field, so substitute your own connection and var. Have fun - Miles Thompson Some messing about with dates = "; echo date ("Y-m-d", $dtAuctionStart ), ""; //$strDate = $dtAuctionStart ; echo "dtAuctionStart : $dtAuctionStart"; $year = substr ($dtAuctionStart, 0, 4); $month =substr( $dtAuctionStart, 4, 2 ); $day = substr ($dtAuctionStart, 6, 2 ); Echo "dtAuctionStart in m-d -y : $month-$day-$year "; $workdate = getdate( $dtAuctionStart ); echo " Workdate Year:", $workdate["year"],""; ?> Ereg Stuff == "; } else { echo "Bad date format. "; } //echo gmdate ("Y-m-d", time()), ""; echo date ("M-d-Y", mktime (0,0,0, $month, $day, $year)); // echo date ("M-d-Y", mktime (0,0,0,12,32,1997)); echo "Local date: " ; echo date ("M d Y H:i:s", time()), ""; echo date ("M d Y H:i:s", time()), ""; echo "Greenwich date: "; echo gmdate ("M d Y H:i:s", time()), ""; echo gmdate ("YmdHis", time()), ""; ?> At 09:35 PM 12/10/2001 -0600, phantom wrote: >What would be an easy what to format a date value into month day year?? >I want to specially display a date stored in mysql in date format >-MM-DD > >The manual says: string date (string format, int [timestamp]) > >I tried $FormattedDate = date("F y, Y",${StoredDate}) > >1999-04-15 spit out December 31, 1969 when I had hoped for April 15, >1999. > >Apparently -MM-DD is not a valid timestamp... i tried mysql formats >of timestamp(8) and timestamp(14) and that didn't work either > > > > >-- >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 formatting
On Monday, December 10, 2001, at 09:35 PM, phantom wrote: > What would be an easy what to format a date value into month day year?? > I want to specially display a date stored in mysql in date format > -MM-DD > > The manual says: string date (string format, int [timestamp]) > > I tried $FormattedDate = date("F y, Y",${StoredDate}) > try $FormattedDate = date("F y, Y",strtotime($StoredDate)); strtotime will convert your -MM-DD string into a unix timestamp. > 1999-04-15 spit out December 31, 1969 when I had hoped for April 15, > 1999. > > Apparently -MM-DD is not a valid timestamp... i tried mysql formats > of timestamp(8) and timestamp(14) and that didn't work either > > > > > -- > 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 formatting
Try using the DATE_FORMAT() function within your SQL query string... $query = "SELELCT DATE_FORMAT (your_date_column, '%M %d %Y') FROM your_table"; where: %M is the month in full text %d is the numerical day of the month with leading zeros %Y is the four digit year Extract the results as ussual... mysql_fetch_row() or mysql_fetch_array() or whatever you would use. Let me know if this works becuase I've not tried it before. Seems like it should work though. Good luck. :-) -Kevin Stone - Original Message - From: "phantom" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, December 10, 2001 8:35 PM Subject: [PHP] Date formatting > What would be an easy what to format a date value into month day year?? > I want to specially display a date stored in mysql in date format > -MM-DD > > The manual says: string date (string format, int [timestamp]) > > I tried $FormattedDate = date("F y, Y",${StoredDate}) > > 1999-04-15 spit out December 31, 1969 when I had hoped for April 15, > 1999. > > Apparently -MM-DD is not a valid timestamp... i tried mysql formats > of timestamp(8) and timestamp(14) and that didn't work either > > > > > -- > 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 formatting in PHP 3.0
From: Paul McGee <[EMAIL PROTECTED]> Date: Thu, Aug 30, 2001 at 12:45:49PM -0400 Message-ID: <[EMAIL PROTECTED]> Subject: Re: [PHP] Date formatting in PHP 3.0 > Thanks, I knew it was something stupid! > > However, the $dy = date ("D", $row[0]) doesn't work. You're welcome... and eh... for the "However, the $dy = date ("D", $row[0]) doesn't work.": It shouldn't. date() requires a timestamp as a second argument, not a string. Unless you retrieve an actual timestamp from your db (which you don't) you could directly feed it to date(). So as long as you get strings from your db you'll have to parse 'm first and then put them through mktime() (like you do in your example). Then you have a real timestamp and you can put that through date(). -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- 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 formatting in PHP 3.0
Thanks, I knew it was something stupid! However, the $dy = date ("D", $row[0]) doesn't work. "* R&Ze:" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > > From: Paul McGee <[EMAIL PROTECTED]> > Date: Thu, Aug 30, 2001 at 12:13:21PM -0400 > Message-ID: <[EMAIL PROTECTED]> > Subject: [PHP] Date formatting in PHP 3.0 > > > I'm looping through a MSQL db pulling out the dates where I would like to > > display the date and then the day of the week. The problem is that every > > date returns the same day of the week, Wed. I checked the documentation and > > it doesn't say anything about the expression only being executed once during > > inside the WHILE loop. > > > > I've tried: > > > > $m = substr($row[0],0,4); > > $d = substr($row[0],5,2); > > $y = substr($row[0],8,2); > > $dy = date ("D", mktime(0,0,0,$m,$d,$y)); > > > > and just using the date field > > > > $dy = date ("D", $row[0]); > > > > Any help would be greatly appreciated! > > > > > > Did you give a look at your own code? > A month consisting of 4 digits? > And a year consisting of 2 digits? > I'd say: > > --- PHP code --- > $y = substr($row[0],0,4); > $m = substr($row[0],5,2); > $d = substr($row[0],8,2); > $dy = date ("D", mktime(0,0,0,$m,$d,$y)); > > and just using the date field > > $dy = date ("D", $row[0]); > --- End of PHP code --- > > > > -- > > * R&zE: > > > > -- > > * R&zE: > > > -- > -- Renze Munnik > -- DataLink BV > -- > -- E: [EMAIL PROTECTED] > -- W: +31 23 5326162 > -- F: +31 23 5322144 > -- M: +31 6 21811143 > -- > -- Stationsplein 82 > -- 2011 LM HAARLEM > -- Netherlands > -- > -- http://www.datalink.nl > -- -- 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 formatting in PHP 3.0
From: Paul McGee <[EMAIL PROTECTED]> Date: Thu, Aug 30, 2001 at 12:13:21PM -0400 Message-ID: <[EMAIL PROTECTED]> Subject: [PHP] Date formatting in PHP 3.0 > I'm looping through a MSQL db pulling out the dates where I would like to > display the date and then the day of the week. The problem is that every > date returns the same day of the week, Wed. I checked the documentation and > it doesn't say anything about the expression only being executed once during > inside the WHILE loop. > > I've tried: > > $m = substr($row[0],0,4); > $d = substr($row[0],5,2); > $y = substr($row[0],8,2); > $dy = date ("D", mktime(0,0,0,$m,$d,$y)); > > and just using the date field > > $dy = date ("D", $row[0]); > > Any help would be greatly appreciated! Did you give a look at your own code? A month consisting of 4 digits? And a year consisting of 2 digits? I'd say: --- PHP code --- $y = substr($row[0],0,4); $m = substr($row[0],5,2); $d = substr($row[0],8,2); $dy = date ("D", mktime(0,0,0,$m,$d,$y)); and just using the date field $dy = date ("D", $row[0]); --- End of PHP code --- -- * R&zE: -- * R&zE: -- -- Renze Munnik -- DataLink BV -- -- E: [EMAIL PROTECTED] -- W: +31 23 5326162 -- F: +31 23 5322144 -- M: +31 6 21811143 -- -- Stationsplein 82 -- 2011 LM HAARLEM -- Netherlands -- -- http://www.datalink.nl -- -- 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 formatting
You need a UNIX timestamp for the second argument in date() - thus you need to first convert your $even into a timestamp (number of seconds past 1970). That would work ... --Joe On Fri, Apr 06, 2001 at 01:13:59PM +0100, Matt Davis wrote: > Hi I am trying to format a date extracted from my DB. I have run my query > and then have used the following to get my row data > > while ($row = mysql_fetch_array($sql_result)) { > $title = $row["message_title"]; > $message = $row["message"]; > $event = $row["date_of_event"]; > > $shortevent = date ("D j M", $event); > > I am trying to take $event and make it diplay like this "FRI 06 APR" using > the date function. Although $event outputs like this "2001-04-06 00:00:00" > $shortevent outputs "Thu 1 Jan" which is unix epoch date. > > Does anybody know what I am doiing wrong its probably something really > simple but I cant see what. > > Matt. > > > -- > 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] /**\ *Joe Stump - PHP/SQL/HTML Developer * * http://www.care2.com - http://www.miester.org - http://gtk.php-coder.net * * "Better to double your money on mediocrity than lose it all on a dream." * \**/ -- 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 formatting
Something I almost always do when pulling dates from a mySQL table is format the date column in the query itself using the mySQL function DATE_FORMAT()... At 01:13 PM 4/6/01 +0100, Matt Davis wrote: >Hi I am trying to format a date extracted from my DB. I have run my query >and then have used the following to get my row data > > while ($row = mysql_fetch_array($sql_result)) { > $title = $row["message_title"]; > $message = $row["message"]; > $event = $row["date_of_event"]; > > $shortevent = date ("D j M", $event); > >I am trying to take $event and make it diplay like this "FRI 06 APR" using >the date function. Although $event outputs like this "2001-04-06 00:00:00" >$shortevent outputs "Thu 1 Jan" which is unix epoch date. > >Does anybody know what I am doiing wrong its probably something really >simple but I cant see what. > >Matt. > > >-- >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 Formatting
At 3:04 PM -0800 2/6/01, Richard Scott Crawford wrote: >Cold Fusion has a wonderful function called CreateODBCDate(), which >takes as an argument any date in just about any format and returns a >standard ODBC date format that you can plug into a database without >worrying about conversion. > >Does PHP have a similar function? I've looked for one but can't >seem to find it anywhere. From http://www.php.net/manual/en/function.strtotime.php - "strtotime - Parse about any english textual datetime description into a UNIX timestamp" If the ODBC timestamp looks like -mm-dd hh:mm:ss then you could do: $Date = '1 jan 2001'; ODBCDate = date('Y-m-d H:i:s', strtotime($Date)); And if you really want, just define the function function CreateODBCDate($DateString) { return date('Y-m-d H:i:s', strtotime($DateString)); } and you can ease your CF-PHP transition :) If you want to default to returning the current date: function CreateODBCDate($DateString='') { return ( $DateString ? date('Y-m-d H:i:s', strtotime($DateString)) : date('Y-m-d H:i:s') ); } Sorry about the weird indent style --- I was trying to avoid wordwrapping. It doesn't specify in the docs, but I _assume_ strtotime() returns false if it can't figure out what the date string is...you might want to test that. - steve >-- >Richard Crawford (mailto:[EMAIL PROTECTED]) >http://www.mossroot.com AIM Handle: Buffalo2K >"Tomorrow, we'll seize the day and throttle it!" -Calvin -- +--- "They've got a cherry pie there, that'll kill ya" --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +-- FBI Special Agent Dale Cooper ---+ -- 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]