Forums

PHP

This topic is locked

Date formatting

Posted 07 Jan 2002 17:55:39
1
has voted
07 Jan 2002 17:55:39 Peter R posted:
Hello again,

Just a quick question I hope. I originally posted this in the official UD newsgroup, but no suggestions as to a solution were made.

In my mysql database I have two date fields, each listed in YYYY-MM-DD (standard MySQL)format.

On a web page where the date is shown to a user, I tried to change the display using the pop-up from the data-binding window.

The different dates should appear like "January 25th, 2002" and "February
24th, 2002"...
But instead, the DIFFERENT dates ALL appear as "November 30th, 1999". Each and every date is the same.

In other words:
2002-01-25 will show-> November 30th, 1999
2002-02-24 will also show-> November 30th...

Any clue why this is happening?

I'm using PHP and Mysql.

Thanks

Peter

Replies

Replied 08 Jan 2002 03:27:35
08 Jan 2002 03:27:35 Tim Green replied:
This is happening because you are storing the date information in a MySQL specific format. This doesn't translate correctly using the standard set of behaviours, as all databases use differing formats.

Instead the Date Formatting options use the Unix timestamp, and the functions expect this data to be retrieved from the database.

I had to do it this way, as otherwise there would have been nearly 200 Server Formats just for the date!

The way around this is to ensure that you are storing the unix timestamp in your field rather than a MySQL-specific date format.

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 08 Jan 2002 16:36:13
08 Jan 2002 16:36:13 Peter R replied:
You made the date formatting options that come standard with UD4?? Cool. Just to ensure clarity, I'm not using an extension.

How do I use a UNIX timestamp? Right now the dates are "expiry dates" so they are entered by hand by a person and then inserted into the db with the rest of the record. What format should I be entering the date as so that it will work correctly?(Can I enter a Unix timestamp by hand?)

Will changing the date format to a Unix timestamp break my current pages? Right now some of my pages hide records older than "today" and thanks to your help earlier I have conditional regions like text that reads "1 day left" which depend on the date field also.

Thanks for any pointers. If the Unix date can't be entered by hand, I'll probably just give up on changing the "displayed date" format.

Peter

Replied 10 Jan 2002 02:26:01
10 Jan 2002 02:26:01 Tim Green replied:
LoL... no I made the Date Formats that come as standard with PHAkT (as well as all of the other Formatting options....)

Now, to create UNIX timestamps is a little tricky if you're going to do it by hand. However (thankfully) PHP has a function that will do it for you.

It is called mktime(). It's a little longwinded to go into here, so take a look at the PHP online reference for this function at :-

www.php.net/manual/en/function.mktime.php

Tim Green

Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>

Reply to this topic