Php Date-Formatting Help

This is a discussion on Php Date-Formatting Help within the PHP Language forums, part of the PHP Programming Forums category; Hello All, I have a date value that I pull from a .csv file. After reading the file and storing ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-06-2006
johndcal@gmail.com
 
Posts: n/a
Default Php Date-Formatting Help

Hello All,

I have a date value that I pull from a .csv file.
After reading the file and storing the values in an array the value of
the date could
be found in $array[1], for example.
================================================== ===========
while (($data = fgetcsv($handle,5000, ",")) !== FALSE) {
$mydate = $data[3]; // here is the array value that holds the date
}
================================================== ===========
The date will be in either m/d/yyyy or mm/dd/yyyy format.
Here is the problem. I need to display this date on the page
in "long" format - i.e. January 5, 2005 instead of 1/5/2005 or
01/05/2005.

I have tried to use the date() function, however I can only get the
formatting to work
with the current date and not with an 'existing' date.

date("d.m.Y", $mydate); // this does not work, I get a date from
1969...

Any advise would be greatly appreciated!

JC

Reply With Quote
  #2 (permalink)  
Old 01-06-2006
Erwin Moller
 
Posts: n/a
Default Re: Php Date-Formatting Help

johndcal@gmail.com wrote:

> Hello All,
>
> I have a date value that I pull from a .csv file.
> After reading the file and storing the values in an array the value of
> the date could
> be found in $array[1], for example.
> ================================================== ===========
> while (($data = fgetcsv($handle,5000, ",")) !== FALSE) {
> $mydate = $data[3]; // here is the array value that holds the date
> }
> ================================================== ===========
> The date will be in either m/d/yyyy or mm/dd/yyyy format.
> Here is the problem. I need to display this date on the page
> in "long" format - i.e. January 5, 2005 instead of 1/5/2005 or
> 01/05/2005.
>
> I have tried to use the date() function, however I can only get the
> formatting to work
> with the current date and not with an 'existing' date.
>
> date("d.m.Y", $mydate); // this does not work, I get a date from
> 1969...
>
> Any advise would be greatly appreciated!
>
> JC


Hi,

advise is simple: RTFM.
Or more friendly: Your answer can be found if you actually read the
functiondefinition at www.php.net.

Here is a part:
date

(PHP 3, PHP 4, PHP 5)
date -- Format a local time/date
Description
string date ( string format [, int timestamp] )

Returns a string formatted according to the given format string using the
given integer timestamp or the current local time if no timestamp is given.
In other words, timestamp is optional and defaults to the value of time().

So what timestamp did you excactly give?
A timestamp is NOT string that represents a date, but a number.

What you need (from the same page at www.php.net) is a function to make a
timestamp from a stringrepresentation of a date. That function is called
strtotime().

Look it up. :-)

Good luck.

Regards,
Erwin Moller
Reply With Quote
  #3 (permalink)  
Old 01-07-2006
Kevin H. Feeley
 
Posts: n/a
Default Re: Php Date-Formatting Help

Erwin Moller wrote:

> johndcal@gmail.com wrote:
>
>> Hello All,
>>
>> I have a date value that I pull from a .csv file.
>> After reading the file and storing the values in an array the value of
>> the date could
>> be found in $array[1], for example.
>> ================================================== ===========
>> while (($data = fgetcsv($handle,5000, ",")) !== FALSE) {
>> $mydate = $data[3]; // here is the array value that holds the date
>> }
>> ================================================== ===========
>> The date will be in either m/d/yyyy or mm/dd/yyyy format.
>> Here is the problem. I need to display this date on the page
>> in "long" format - i.e. January 5, 2005 instead of 1/5/2005 or
>> 01/05/2005.
>>
>> I have tried to use the date() function, however I can only get the
>> formatting to work
>> with the current date and not with an 'existing' date.
>>
>> date("d.m.Y", $mydate); // this does not work, I get a date from
>> 1969...
>>
>> Any advise would be greatly appreciated!
>>
>> JC

>
> Hi,
>
> advise is simple: RTFM.
> Or more friendly: Your answer can be found if you actually read the
> functiondefinition at www.php.net.
>
> Here is a part:
> date
>
> (PHP 3, PHP 4, PHP 5)
> date -- Format a local time/date
> Description
> string date ( string format [, int timestamp] )
>
> Returns a string formatted according to the given format string using the
> given integer timestamp or the current local time if no timestamp is
> given. In other words, timestamp is optional and defaults to the value of
> time().
>
> So what timestamp did you excactly give?
> A timestamp is NOT string that represents a date, but a number.
>
> What you need (from the same page at www.php.net) is a function to make a
> timestamp from a stringrepresentation of a date. That function is called
> strtotime().
>
> Look it up. :-)
>
> Good luck.
>
> Regards,
> Erwin Moller


The route I take with date formatting from the mm/dd/yyyy or dd/mm/yyyy
formats is generally:

list($month,$day,$year)=explode("/",$mydate);
echo(date("F jS, Y",mktime(0,0,0,$month,$day,$year)));

Kevin
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 11:44 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0