/    Sign up×
Community /Pin to ProfileBookmark

date display help please

In my SQL database I have a date field.

As far as I can tell it has to be in the format YYYY-MM-DD.

On a web page how do I display it in the format DD-MM-YYYY.
That’s the same way as on this forum.

Your help is appreciated.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@shimonJun 14.2004 — yeah, I know that feeling ?

[code=php]function format_date($string)
{
$parts = explode("-", $string);
return $parts[2]."-".$parts[1]."-".$parts[0];
}

$mysql_date = "2004-06-14";
$display_date = format_date($mysql_date);
echo $display_date;[/code]

should do it nicely, though international users may wish to shuffle the order of the parts to suit the conventions in their part of the world ?
Copy linkTweet thisAlerts:
@krystoffJun 14.2004 — hi,

just have a look in the php manual for strtotime() ?

you gonna find wht you want

somethinh like :
[code=php]
mysql_fetch_assoc($result);
$date_d=date('d/m/Y', strtotime($result['date']));
echo date_d;
[/code]

maybe

Krystoff
Copy linkTweet thisAlerts:
@aoeguyJun 15.2004 — You could use a timestamp for it to be easier for people to change them.

The function would be [b]time()[/b]

When you insert it to the table, use

'INSERT INTO table (bla, time) VALUES ("text",'.time().')';

when you get it from the table, format it like this:
[code=php]
$format = $users_set_format_or_whatever; // Well it doesnt have to be
$sql = 'SELECT * FROM table WHERE............';
$result = mysql_query($sql);
$result = mysql_fetch_array($result);

$date_to_display = date($format, $result['time']);
[/code]


You can alter the code as much as you want, I just wanted to give an example ?

the format could be for example:
[code=php]
$users_set_format_or_whatever = 'd/m/y';
[/code]


Hope this helped...

AoEGuy
Copy linkTweet thisAlerts:
@charterauthorJun 15.2004 — [i]Originally posted by aoeguy [/i]

[B]You could use a timestamp for it to be easier for people to change them.



The function would be [b]time()[/b]



When you insert it to the table, use

'INSERT INTO table (bla, time) VALUES ("text",'.time().')';

when you get it from the table, format it like this:

[code=php]
$format = $users_set_format_or_whatever; // Well it doesnt have to be
$sql = 'SELECT * FROM table WHERE............';
$result = mysql_query($sql);
$result = mysql_fetch_array($result);

$date_to_display = date($format, $result['time']);
[/code]


You can alter the code as much as you want, I just wanted to give an example ?

the format could be for example:
[code=php]
$users_set_format_or_whatever = 'd/m/y';
[/code]


Hope this helped...

AoEGuy [/B][/QUOTE]


2 problems seem to occur to me here. I believe [B]Timestamp[/B] will only work on UNIX systems. I am using Windows XP and no nothing about UNIX.

Also I don't wish for it to be that day's date. I wish it to put a week ending date on my web page.
×

Success!

Help @charter spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...