Formatting of dates and times of MySQL

I have a few questions that I hope you guys can help out me with...

I have a MySQL DB that includes the columns 'date' and 'start_time', 'end_time '.  Date is stored as 'date' and start_time and end_time are stored as 'time '.

When formatting a date in PHP, I found this page very useful: http://php.net/manual/en/function.date.php

Does anyone know of a similar page showing the attributes that are available with the MySQL DATE_FORMAT.

Also, I currently have the query written like this:

SELECT id, title, description, DATE_FORMAT ('date', '% m/%d') AS formatted_date, start_time, end_time, location

Events


Does anyone know how I can format the columns of TIME similar to how I did the DATE columns?  I once stored as '08:00:00 ' and "21:30:00" and I want displayed them as '08:00 ' and «21:00»


Any help? Thank you!

The full list of formatting specifiers is in MySQL documentation at http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_date-format.

Use DATE_FORMAT()) for your time columns.

DATE_FORMAT(theTime, '%l:%i%p') AS formatted_time

I think MySQL is using AM and PM. If you want to lower case, just pass the result of the database to strtolower():


Tags: Dreamweaver

Similar Questions

  • Date (date and time) with MySQL, register here!

    Hello

    Summary:

    I have a page (form) to capture traffic. It works, it allows the user to enter details of attendance. Click, he writes to the database - table. The date is not entered on the form. I want to date this stamp by inserting a date (date and time - declared field). I'll give you the source code. Please pin point what code I'd be inserting and assuming that everything in this code.

    Question:

    Insert the date and time in the database table-

    Code:

    <? php require_once('Connections/dbAttendance.php');? >

    <? PHP

    If (! function_exists ("GetSQLValueString")) {}

    function GetSQLValueString ($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

    {

    If (via PHP_VERSION < 6) {}

    $theValue = get_magic_quotes_gpc()? stripslashes ($TheValue): $theValue;

    }

    $theValue = function_exists ("mysql_real_escape_string")? mysql_real_escape_string ($TheValue): mysql_escape_string ($theValue);

    Switch ($theType) {}

    case 'text ':

    $theValue = ($theValue! = "")? « " ». $theValue. "" "": "NULL";

    break;

    case "long":

    case "int":

    $theValue = ($theValue! = "")? intval ($TheValue): 'NULL ';

    break;

    case "double":

    $theValue = ($theValue! = "")? doubleVal ($TheValue): 'NULL ';

    break;

    case "date":

    $theValue = ($theValue! = "")? « " ». $theValue. "" "": "NULL";

    break;

    case "set":

    $theValue = ($theValue! = "")? $theDefinedValue: $theNotDefinedValue;

    break;

    }

    Return $theValue;

    }

    }

    $editFormAction = $_SERVER ['PHP_SELF'];

    If (isset {}

    $editFormAction. = « ? ». htmlentities($_SERVER['QUERY_STRING']);

    }

    If ((isset($_POST["MM_insert"])) & & ($_POST ["MM_insert"] == 'form')) {}

    $insertSQL = sprintf ("INSERT INTO attendlist (IDWindows, title, first name, name, mobile extension, jobrole, courses, GIC, mgrname, room) VALUES (%s, %s %s, %s, %s, %s, %s, %s, %s, %s, %s)", ")

    GetSQLValueString ($_POST ["'textfield"], "text").

    GetSQLValueString ($_POST ['select'], "text").

    GetSQLValueString ($_POST ['textfield2 "],"text").

    GetSQLValueString ($_POST ['textfield3'], "text").

    GetSQLValueString ($_POST ['textfield4'], "text").

    GetSQLValueString ($_POST ['textfield5'], "text").

    GetSQLValueString ($_POST ['choisies5'], "text").

    GetSQLValueString ($_POST ["select2"], "text").

    GetSQLValueString ($_POST ['select4'], "text").

    GetSQLValueString ($_POST ['textfield7'], "text").

    GetSQLValueString ($_POST ['select3'], "text"));

    @mysql_select_db ($database_dbAttendance, $dbAttendance);

    $Result1 = mysql_query ($insertSQL, $dbAttendance) or die (mysql_error ());

    $insertGoTo = "Thankyou.php";

    If (isset {}

    $insertGoTo. = (strpos ($insertGoTo, '?'))? « & » : « ? » ;

    $insertGoTo. = $_SERVER ['QUERY_STRING'];

    }

    header (sprintf ("location: %s", $insertGoTo));

    }

    @mysql_select_db ($database_dbAttendance, $dbAttendance);

    $query_rsAttendance = "SELECT * from attendlist";

    $rsAttendance = mysql_query ($query_rsAttendance, $dbAttendance) or die (mysql_error ());

    $row_rsAttendance = mysql_fetch_assoc ($rsAttendance);

    $totalRows_rsAttendance = mysql_num_rows ($rsAttendance);

    ? >

    < ! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional / / IN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > ""

    " < html xmlns =" http://www.w3.org/1999/xhtml ">

    < head >

    < meta http-equiv = "Content-Type" content = text/html"; charset = utf-8 "/ >"

    < title > delegate registry < /title >

    < link href = "Registerpage.css" rel = "stylesheet" type = "text/css" / > "

    < link href = "SpryAssets/SpryValidationTextField.css" rel = "stylesheet" type = "text/css" / > "

    < link href = "SpryAssets/SpryValidationSelect.css" rel = "stylesheet" type = "text/css" / > "

    < script src = "SpryAssets/SpryValidationTextField.js" type = "text/javascript" > < / script > "

    < script src = "SpryAssets/SpryValidationSelect.js" type = "text/javascript" > < / script > "

    < / head >

    <? PHP

    $date = date ("format", $timestamp);

    ? >

    < body >

    < div class = "container" >

    < div class = "header" > < img src = "Identify Imperial2.jpg" width = "960" height = "150" alt = "" / > <! - end .header - > < / div > "

    < div class = "content" >

    Registry < H3 >: <? PHP echo "Date -".date("d/m/y - H:ia"). > < / h3 >

    < do action = "<?" PHP echo $editFormAction;? ">" method = "post" name = "form" >

    < table width = "780" border = "0" >

    < b >

    < td > < div align = "right" > user ID * < / div > < table >

    < td > < span id = "sprytextfield1" >

    < input name = "textfield" type = "text" id = "textfield" tabindex = "1" size = "18" maxlength = "10" / >

    < span class = "textfieldRequiredMsg" > a value is required. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > title * < / div > < table >

    < td > < span id = "spryselect1" >

    < select name = "select" id = "select" tabindex = "2" >

    < option value = '0' > select < / option >

    < option value = "1" > Ms < / option >

    < option value = "2" > Ms < / option >

    < option value = "3" > Mdm < / option >

    < option value = "4" > Dr. < / option >

    < option value = "5" > Mr < / option >

    < option value = "6" > Professor < / option >

    < / select >

    < span class = "selectRequiredMsg" > please select an item. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > name * < / div > < table >

    < td > < span id = "sprytextfield2" >

    < input name = "textfield2" type = "text" id = "textfield2" tabindex = "3" size = "30" maxlength = "30" / >

    < span class = "textfieldRequiredMsg" > a value is required. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > family name * < / div > < table >

    < td > < span id = "sprytextfield3" >

    < input name = "textfield3" type = "text" id = "textfield3" tabindex = "4" size = "30" maxlength = "30" / >

    < span class = "textfieldRequiredMsg" > a value is required. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > Contact / beep * < / div > < table >

    < td > < span id = "sprytextfield4" >

    < input name = "textfield4" type = "text" id = "textfield4" tabindex = "5" size = "30" maxlength = "30" / >

    < span class = "textfieldRequiredMsg" > a value is required. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > Mobile no: (optional) < / div > < table >

    < td > < input name = "textfield5" type = "text" id = "textfield5" tabindex = "6" size = "20" maxlength = "20" / > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > function * < / div > < table >

    < td > < span id = "spryselect5" >

    < select name = "choisies5" id = "choisies5" tabindex = "7" >

    < option value = '0' > select < / option >

    < option value = "1" > doctor < / option >

    < option value = "2" > nurse IP < / option >

    < option value = "3" > nurse OP < / option >

    < option value = "4" > midwife < / option >

    < option value = "5" > booking clerk < / option >

    < option value = "6" > medical Secretary < / option >

    < option value = "7" > OP receptionist < / option >

    < option value = "9" > CNS/NP < / option >

    < option value = "10" > test < / option >

    < / select >

    < span class = "selectRequiredMsg" > please select an item. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > manager name * < / div > < table >

    < td > < span id = "sprytextfield5" >

    < input name = "textfield7" type = "text" id = "textfield7" tabindex = "8" size = "30" maxlength = "30" / >

    < span class = "textfieldRequiredMsg" > a value is required. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > course * < / div > < table >

    < td > < span id = "spryselect2" >

    < select name = "select2" id = "select2" tabindex = "9" >

    < option value = '0' > select < / option >

    < option value = "1" > demo < / option >

    < option value = "2" > doctors < / option >

    < option value = "9" > CNS/NP < / option >

    < option value = "3" > nurse IP < / option >

    < option value = "4" > nurse OP < / option >

    < option value = "5" > midwife < / option >

    < option value = "6" > booking clerk < / option >

    < option value = "7" > medical Secretary < / option >

    < option value = "8" > OP receptionist < / option >

    < / select >

    < span class = "selectRequiredMsg" > please select an item. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > location * < / div > < table >

    < td > < span id = "spryselect3" >

    < select name = "select3" id = "select3" tabindex = "10" >

    < option value = '0' > select < / option >

    < option value = "1" > CHX 12 floor Rm 1 < / option >

    < option value = "2" > CHX 12 Floor Rm 2 < / option >

    < option value = "3" > CHX 10 West < / option >

    < option value = "4" > HH N207 < / option >

    < option value = "5" > HH W12 Conference < / option >

    < option value = "6" > Rm SMH one < / option >

    < option value = "7" > Rm SMH b < / option >

    < option value = "8" > SMH Ming wing Rm 5 < / option >

    < option value = "9" > SMH Ming wing Rm 3 < / option >

    < / select >

    < span class = "selectRequiredMsg" > please select an item. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "right" > GIC * < / div > < table >

    < td > < span id = "spryselect4" >

    < select name = "select4" id = "select4" tabindex = "11" >

    < option value = '0' > select < / option >

    < option value = "1" > GIC 1 - medicine < / option >

    < option value = "2" > GIC 2 - surgery and Cancer < / option >

    < option value = "3" > GIC 3 - specialized Services < / option >

    < option value = "4" > GIC 4 - Services circulatory and renal medicine < / option >

    < option value = "5" > GIC 5 - women and children < / option >

    < option value = "6" > GIC 6 - clinic and investigation Sciences < / option >

    < option value = "7" > GIC 7 - private Patients < / option >

    < option value = "8" > other < / option >

    < / select >

    < span class = "selectRequiredMsg" > please select an item. </span > < / span > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < table >

    < td > < input name = "button" type = "submit" id = "button" value = "Submit" / > < table >

    < td > < table >

    < /tr >

    < b >

    < td > < div align = "center" > * mandatory fields < / div > < table >

    < td > < table >

    < td > < table >

    < /tr >

    < /table >

    < input type = "hidden" name = "MM_insert" value = "form" / >

    < / make >

    <! - end content - > < / div >

    < div class = "footer" >

    < p align = "center" >

    " < a href =" http://validator.w3.org/check?URI=referer "> < img ".

          src=" http://www.w3.org/icons/valid-Xhtml10 "alt ="Valid XHTML 1.0"Transitional height ="31"width ="88"/ > < / a > "

    < p align = "center" > Cerner@Imperial ICT training team < /p >

    < /p >

    <! - end .footer - > < / div >

    <! - end .container - > < / div >

    < script type = "text/javascript" >

    var sprytextfield1 = new Spry.Widget.ValidationTextField ("sprytextfield1", "none", {validateOn: ["blur", "change"]});

    var spryselect1 = new Spry.Widget.ValidationSelect ("spryselect1", {validateOn: ["change", "blur"]});

    var sprytextfield2 = new Spry.Widget.ValidationTextField ("sprytextfield2", "none", {validateOn: ["blur", "change"]});

    var sprytextfield3 = new Spry.Widget.ValidationTextField ("sprytextfield3", "none", {validateOn: ["blur", "change"]});

    var sprytextfield5 = new Spry.Widget.ValidationTextField ("sprytextfield5", "none", {validateOn: ["blur", "change"]});

    var spryselect2 = new Spry.Widget.ValidationSelect ("spryselect2", {validateOn: ["change", "blur"]});

    var spryselect3 = new Spry.Widget.ValidationSelect ("spryselect3", {validateOn: ["change", "blur"]});

    var spryselect4 = new Spry.Widget.ValidationSelect ("spryselect4", {validateOn: ["change", "blur"]});

    var sprytextfield4 = new Spry.Widget.ValidationTextField ("sprytextfield4", "none", {validateOn: ["blur", "change"]});

    var spryselect5 = new Spry.Widget.ValidationSelect ("spryselect5", {validateOn: ["blur", "change"]});

    < /script >

    < / body >

    < / html >

    <? PHP

    mysql_free_result ($rsAttendance);

    ? >

    There are several ways. One is to get the date of the php time() function and use it in your insert statement. Another is to use the MySQL CURDATE () function. But probably the easiest and best are simply set the default value for the column of date / time than the current date/time and exclude it from the insert statement. No required code changes.

    http://dev.MySQL.com/doc/refman/5.0/en/timestamp-initialization.html

  • How the taskbar to view the Long format of Date and time? I know that I can click to see, but I want it appear constantly.

    Can someone guide me through these steps.

    1. right click on the bar of tasks then UN -lock the taskbar if there is a tick against this setting.

    2 place your cursor on the top edge of the taskbar until it turns into a two-headed arrow, and then click on & made drag as if you were dragging the edge of any window.  By making the taskbar more fat, you will see the format switch to a view of three lines: hour, day of the week, short date.  This is the best that this point can do on its own, so I don't think it will satisfy you.

    3 you can then upgrade by clicking on the time in the taskbar, click on change date & time..., Date & time tab, click change date, time, Date & settings dialog box, click on change the calendar settings, in the entry for the short date format, enter what you want as DD MMMM yyyy then OK OK, OK, OK.  The taskbar happily modified displays short date in the format.

    4 you can easily try then reset then using the reverse procedure, if you decide that the display of three lines is worse than any date not having do not at all.

  • Date and time in a table of numbers - is it possible?

    Hello

    I have a table with specific measurement data of float and I save it in a spreadsheet, so that I can easily open it with Excel.

    Now, I want to win the date of the end of time as well.

    To achieve this, I changed the table of double chain and converted into all the numbers and the date and time strings, but it is not very economical.

    Can I record the date and time in a digital format, which excel can interpret as the date and time?

    I think the following:

    These numbers:

    39303 0,66134502

    converted to the format of date and time in excel are:

    09.08.2007 15:52:20

    How to convert date and time to numbers in LabVIEW, so that excel can convert to the date and time again?

    Johannes

    LabVIEW 7.1 (!)

    Hi Johannes,

    This link should help.

    http://www.Ozgrid.com/Excel/ExcelDateandTimes.htm

    Mike

  • Date and time of file Excel data import

    I'm running into problems of import of dates-hours format 15/03/2010 21:30 using SQL Developer. In step 1 of the import data wizard, the data preview window displays all fields date dates Excel (for example, 40252.89583 instead of 15/03/2010-21:30). I can SQL Developer to recognize the data in the format of date and time, rather than convert them to decimal values?

    When you import from Excel, I have not found a date format model that would transform their decimal number into a date Oracle. But the following seems to work well:

    1. save the Excel page in a CSV file, and then in the import wizard SD, you can enter the date format for this column model.

    2. in Excel convert this column of text. (Highlight your date column, choose the menu item 'Data', 'Data tools' group choose the 'Text to columns' tool, click next / next / then click on the 'Text' button, click on 'Finish' and save your xls) Now in the import of SD Wizard simply enter the date format model that corresponds to the column of 'text' Excel with your dates.

    Anyway seems to work for me.

  • I want to change the file name format "save under" so the date and time are first.

    When I select a few emails and then select "Save as" to keep a copy on my computer, the name of the file that is created has the date and time at the end of the file name of the email.
    Sample "save under" file name: "Habitat Follow Up - Bryan ([email protected]) - 2011-11-15 0744.eml.
    Is it possible to change the structure or format of the file name if the date and time of the email are initially the file name?

    Try ImportExportTools and customize the format of the file name in the options.

    http://chrisramsden.vfast.co.UK/3_How_to_install_Add-ons_in_Thunderbird.html

  • date and time of the Windows mail format

    Windows Mail is not affected by my Date and time formats in the locale in the Vista SP2 x 64 and keeps display US formats (12 hr clock and date day/month/year format. I'm in Norway, and we use the formats of European time date: day/month/year for dates and 24 hour time clock. How can I make Windows Mail conform to these local formats?
    Concerning
    Trond Ruud,
    Norway

    Hello

    Lava K to refer to the thread below which might help you.

    http://answers.Microsoft.com/en-us/Windows/Forum/windows_vista-desktop/time-stamp-on-outgoing-emails/d046ddd5-d337-47ac-bbbe-8dbbb80eca61

  • Date and time format policies in vWorkspace environment.

    Hi team,

    is there any policy to format date and time controller for user VDI in v Workspace. some financial request different date and time format including suite can for their excellent work environment.

    Thank you

    Hi Ravi,

    We have a section of time zones in the vWorkspace Management Console that allows you to set the time zone.

    You can attribute that to the target as you would with applications etc.

    Thank you, Andrew.

  • I have a registration error trying to download a disc. It is said, your operating system Date and time format do not match the expected for PM Fastrack run format.

    Error in saving of the PM FASTrack.
    Impossible to analyze the dayYour operating system Date and time format do not match the expected for PM FASTrack run format. The format should be mm/dd/yyyy hh: mm:. The format is

    It's my complete error message. The time is set in this format on the computer. How should I do?

    Hello Murphy,

    Thanks for posting your question on the Forums of community of Microsoft.
    From the description of the question, I understand this format date and time do not match for PM FASTrack run.
    Let me go ahead and help you with the issue.
     
    You did changes to the computer before the show?
     
    I suggest for the link and follow the steps in the article, and check if this can help:
    Change the display of dates, times, currencies, and measures
     
    Also, check out the support links:
    PM FASTrack support.
     
    I hope this helps. If you have any other queries/issues related to Windows, write us and we will be happy to help you further.
  • Form Validation failure: "value is not a date and time in the format"

    Hello world

    I am facing a weird problem in my custom OAF page. I'm displaying the records of a particular table through dynamic VO and dynamic array. All records appear correctly. But when I try to click on NEXT 10 records in a table, I get the error like "FAILED FORM VALIDATION: 1000 ORG CUST BO VERSION is not a date and time in the format. Just like in the screenshot below.

    DESKTOP.JPG

    Strange part of the question, if I select the columns to display not related to this day, so I only am not facing problems. If I select only dates to display and also am not facing this problem. If I use the mixture of this type varchar2 and data, I get this error.

    I tried to change the type of data but no use.

    If we close, look at the PARTY_ID error message trying to copy its data to ORG_CUST_BO_VERSION the last column. Why what's happening clue me less. Can anyone guide me on this please?

    The problem is that you use the same name for the creation of the MessageTextInputBean inside the Table.

    The name of MessageTextInputBean make it dynamic.

    ex: -.

    OAMessageTextInputBean oamessage = (OAMessageTextInputBean) createWebBean (pageContext,

    MESSAGE_TEXT_INPUT_BEAN,

    NULL,

    'text' + columnNo);

    See you soon

    AJ

  • Date.MinValue to format date and time in the MAF

    Hello

    For the amx:inputdate component, I want to display the date and time format. I need to be able to select the date and time.

    Can someone help me please in obtaining it. If items available, please share me.

    Thank you

    Rita

    If you just want to show the date or time, or both, then you change the attribute 'type' to date. MinValue

    To date. MinValue on iOS, a native component selector is used for this purpose. On Android, there is a date component. MinValue AMX used.

    You can check the link below for how it will look like

    https://wikis.Oracle.com/display/ADFMobileDesign/component+-+input+date

  • Date and time format: alert call RIDC

    Hello
    I want to define the features of date and time on my paper, how can I get the date and time of CRMI call

    Concerning
    Mayur Mitkari

    Hi Mayur, I also work on request CRMI. In my case I'll put in dInDate for a new record using this piece of code:

    binder.getLocalData () .setDate ("dInDate", new SimpleDateFormat ("dd/MM/yy hh: mm") .parse (this.fecPub));

    In this way, I put date custom in my bean var «fecPub» dInDate I hope this can give you a hint to get your app working.

    Greetings

  • Evil of the formats of date and currency in the Sierra

    I'm on MacOS in English, but I want the region settings to reflect the country I live in.

    After the passage of El Capitan in Sierra, date and currency formats broke. For example, if you set the region of Finland, the date format should be 26.9.2016 instead of 26/09/2016. Also the currency symbol must appear after the value, 4 €567,89 instead of €4 567,89.

    Days of week and months are untranslated.

    Have you checked the tab 'Advanced' for date and time formats?

    Just after the upgrade, I found that the short format for the date has been reset to include slashes, whereas I had previously removed them.

    My region is set to the Germany, but with the main system language set to English, the months and days of the week are in English. I can't find a way to change this.

  • As of the 31 version, why is there still no option of Thunderbird to insert the date and time in the message that you write?

    As of the 31 version, why is there still no option of Thunderbird to QUICKLY insert the date and time in the message that you write?

    Literally, saw this option very well needed - and opportunity-"promise" for three years now, and even if there are only one or two formats that could be used, at least the option is there.

    It seems that only is to bind a Macro, and the tool to Thunderbird and do it this way.

    Joe Rotello
    [email protected]
    Skype: joerotello

    If the installation of the add-on of TimeStamp is unacceptable for see you if there is a related add-on that you that you already might have managed to convince author to add your function. The Add on more for example has many variables that can enter the body of the message that get automatically replaced with the appropriate data when you merge a message.

  • How to export my history of travel (including the date and time) to a text file?

    I need to collect data on the amount of time I spend on specific sites, research on my thesis topic. In my browsing history data. I need a way to export the data from the history file including the date and time information in a format that is easy to parse (.txt file delimited by commas, etc.)

    You are welcome

Maybe you are looking for