close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

How do I change the date format

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

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

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...