Jump to content

Archived

This topic is now archived and is closed to further replies.

sun14php

yyyy-mm-dd to dd-mm-yy

Recommended Posts

Q1.how do i display mysql yyyy-mm-dd date into browse as dd-mm-yy format using php or whatever ?
Q2. can set input-mask in html's textbox to accept date as dd-mm-yy ?

Share this post


Link to post
Share on other sites
I'm not very sure what you mean, but this is the date format you wants.

[code]date(d-m-y);[/code]

Please refer to [a href=\"http://sg.php.net/date\" target=\"_blank\"]http://sg.php.net/date[/a] for more informations.

Share this post


Link to post
Share on other sites
You can use explode()...

[code]<?php
//$date is in yyyy-mm-dd format
$explode=explode("-",$date);
$new_date=$explode[2]."-".$explode[1]."-".$explode[0];
echo $new_date;
?>[/code]

Orio.

EDIT-
And if you want to convet yyyy to yy, do this:
[code]<?php
//$date is in yyyy-mm-dd format
$explode=explode("-",$date);
$explode[0]=substr($explode[0], -1, 2);
$new_date=$explode[2]."-".$explode[1]."-".$explode[0];
echo $new_date;
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.