472,327 Members | 1,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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

Jan 6 '06 #1
2 2024
jo******@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
Jan 6 '06 #2
Erwin Moller wrote:
jo******@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
Jan 7 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tjerk | last post by:
Hello all, I have the script below to change an image depending on the date upto january it worked fine but then it just stopped working does...
9
by: Thomas R. Hummel | last post by:
Hello, I am importing data that lists rates for particular coverages for a particular period of time. Unfortunately, the data source isn't very...
30
by: Dr John Stockton | last post by:
It has appeared that ancient sources give a method for Numeric Date Validation that involves numerous tests to determine month length; versions are...
3
by: captain | last post by:
Below is the sql for data with same date need to extract + or - 5 days data of same date also. How to also get data of + and - days related to...
1
by: Wayne | last post by:
Hi all I'm trying to calculate the number of days (or workdays) between 2 given dates that do not include weekend days or public holidays...
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error...
6
by: Luvin lunch | last post by:
Hi, I'm new to access and am very wary of dates as I have limited experience in their manipulation and I know if they're not done properly...
4
by: Buzby | last post by:
I want a drop down date selection box on a form in the format of Mon 18 June 2007, that will go say 400 days in advance from the current date. ...
10
by: Jes | last post by:
Dear all I have a date field on a HTML form where the user is asked to key in dd/mm/yyyy However, when that is written to MySql it is either not...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This...
0
by: tammygombez | last post by:
Hey fellow JavaFX developers, I'm currently working on a project that involves using a ComboBox in JavaFX, and I've run into a bit of an issue....
0
by: tammygombez | last post by:
Hey everyone! I've been researching gaming laptops lately, and I must say, they can get pretty expensive. However, I've come across some great...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This happens in runtime 2013 and 2016. When a report is run and then closed a toolbar shows up and the only way to get it to go away is to right...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...

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.