close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

How do I change the date format

Thread begun 3/04/2010 3:47 pm by account134484 | Last modified 5/16/2010 2:26 pm by jebrandon343719 | 1953 views | 4 replies |

account134484

How do I change the date format

How do I change the mysql date format from yyyy-mm-dd to mm-dd-yyyy on the results and details pages.

Also how do I add the day of the week for this date column
<?php echo($row_WADAhomework['due_date']); ?>

This the page I am working on.
homework_Results.php

Thank you

Sign in to reply to this post

anonymous

The best way to do this would be with a function... you can add an include to the top of all your pages such as corefuncs.php is what I like to use and then I include all my functions on what page.

Here's a couple of functions I wrote - you may need to modify the delimiters to get the display exactly as you want it.

The first one is what I use to convert standard date format (mm/dd/yyyy) into database format (yyyy-mm-dd):

// DATABASE DATE CONVERSION (ASSUMES DATE FORMAT IS MM/DD/YYYY)

function databaseDate($datetoconvert) {
$dateDataDate = explode('/', $datetoconvert);
$dateDataYear = $dateDataDate[2];
$dateDataMonth = $dateDataDate[0];
$dateDataDay = $dateDataDate[1];
$dataDateFinal = $dateDataYear.'-'.$dateDataMonth.'-'.$dateDataDay;
return $dataDateFinal;
}


This works by first setting the input of a date field to only accept mm/dd/yyyy through validation... then on the actual database update field, modify the data like this: databaseDate($_POST['datefield']

Remember that the function page include must occur before you call the function which is why I typically will call my functions in the first line of every page before anything else.

For the display, it works the same, but I use this function:

// DATE FUNCTION

function displayDate($datetochange) {
if ($datetochange != "0000-00-00") {
$date_var = strtotime($datetochange);
echo date('m/d/Y', $date_var);
} else {
echo '';
}

}

So, now just call the function and then use it like this:

<?php displayDate($row_WADAhomework['due_date']); ?>


In your case, you may want to modify that function's formatting from m/d/Y to read m-d-Y.

Best regards,

Brian

Sign in to reply to this post

account134484

Update

Thanks Brian.

Would I put both functions in the same file?

Also, do you have an answer to displaying the day of the week of the db date that was inserted?

Thanks,
Josh

Sign in to reply to this post

jebrandon343719

date from serach page to results page

Hi Brian,
Thanks for this function.
Can you explain how I would take a date entered in a search page as dd/mm/yyyy and convert it ready for a results page that requires a database format of yyyy-mm-dd

Ta

Sign in to reply to this post

jebrandon343719

Got it working

Hi Brian,
I got this to work! Thought I'd share this one.

To convert a date from dd/mm/yy ready for a search page results which expects yyyy-mm-dd.

I added this code in the results page immedialty prior to the "comparison list additions"

if ($_GET["S_newsdate"]!="" && $_GET["S_newsdate"]!="0") {
function databaseDate($datetoconvert) { //v2.0
$dateDataDate = explode('/', $datetoconvert);
$dateDataYear = $dateDataDate[2];
$dateDataMonth = $dateDataDate[1];
$dateDataDay = $dateDataDate[0];
$dataDateFinal = $dateDataYear.'-'.$dateDataMonth.'-'.$dateDataDay;
return $dataDateFinal;
}
$_GET["S_newsdate"] = databaseDate($_GET["S_newsdate"]);
}

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...