473,503 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2148
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
4135
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 anybody have an idea how I can make it work again or...
9
2621
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 clean. I've come up with some rules that I think...
30
3637
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 often posted by incomers here. That sort of code...
3
2560
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 same date. SELECT IM.Area, IM.Location,...
1
6116
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 (public holidays are user defined from a dbase, have a...
12
29422
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 through an asp.net custom validator, it is as...
6
12524
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 things can turn ugly quickly. I would like to use a...
4
2994
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. Can anyone point me in the right direction as I...
10
2527
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 accepted or another value is tored in the...
30
5643
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 problem happens in either Access or SQL Server. In the...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7282
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7339
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7463
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5581
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5017
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
738
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.