Ask a Question related to Dreamweaver AppDev, Design and Development.

  1. #1

    Default Date display format

    I know how to change the way the date varible displays but how can I change the way a recordset date field displays? I would like it to look like "May 16th 2005."
    erickia Guest

  2. Similar Questions and Discussions

    1. Date Format in Com+
      Hi All, I have one Component in VB6. My component receive a date as string parameter ("dd/MM/yyyy"). My componente understand "MM/dd/yyyy". Then I...
    2. PHP date format
      Accoding to the manual, if I want to display the a date in the format "May 31st, 2005 I should use the following code: <p> The event will held on...
    3. Date Format pb
      Hi, Got a pb with american date format MM/dd/YYYY. My WebService Method convert String to Date. It works good except for one case : 1/5/2005 ...
    4. format date
      i have a date stored in my db in this format: 2005-03-15 00:00:00.000 however, i want to display this date on my .asp page in this format: 03/05...
    5. converting date into database date format(newbie)
      Hi! U can convert "8-Aug-03" into mysql date which requires yyyy-mm-dd format as below. <?php date("Y-m-d",strtotime("8-Aug-03")); ?>
  3. #2

    Default Re: Date display format

    erickia wrote:
    > I know how to change the way the date varible displays but how can I change the way a recordset date field displays? I would like it to look like "May 16th 2005."
    When asking questions like this, it's important to say which database
    system you're using, because they all have different ways of doing it. I
    happen to know from another post that you're using MySQL, so the answer
    is simple:

    SELECT column1, column2, DATE_FORMAT(date_column, '%M %D %Y')
    FROM table

    You can find details of the MySQL DATE_FORMAT function here:

    [url]http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html#id2851311[/url]

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  4. #3

    Default Re: Date display format

    I'm sorry. I obviously don't know enough to ask the question properly.
    Dreamweaver created the following line when I insterted a field on the page.

    <?php echo $row_Recordset1['SaleDate']; ?>

    Where would I put the formating parameters. I'm assuming that at this point
    they would be PHP rather then MySQL.

    erickia Guest

  5. #4

    Default Re: Date display format

    erickia wrote:
    > Where would I put the formating parameters. I'm assuming that at this point
    > they would be PHP rather then MySQL.
    <?php echo date($row_Recordset1['SaleDate'],'F jS Y'); ?>

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  6. #5

    Default Re: Date display format

    Hmmm!!! Seems like that should have worked but it didn't. I had changed a line in the php.ini file about using the MySQL date instead of the PHP default. I'll try changing that back.
    erickia Guest

  7. #6

    Default Re: Date display format

    No, it is still displaying:
    2002-09-18 00:00:00
    erickia Guest

  8. #7

    Default Re: Date display format

    erickia wrote:
    > No, it is still displaying:
    > 2002-09-18 00:00:00
    Hang on a moment. Of course, it will. The PHP date() function requires a
    PHP timestamp, not a MySQL date or timestamp.

    MySQL produces dates in a standard format, but if you have used a MySQL
    timestamp, the format changed with the introduction of MySQL 4.1. Unless
    I know what $row_Recordset1['SaleDate'] produces, I can't to create a
    PHP function to handle it.

    The most sensible approach is what I suggested in the first place -
    rewrite your SQL query so that the formatting is done by MySQL (that's
    what it's for).

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  9. #8

    Default Re: Date display format

    erickia wrote:
    > I had changed a line in the php.ini file about using the MySQL date instead of the PHP default. I'll try changing that back.
    There is no setting in php.ini for changing the MySQL date. There is one
    for MSSQL, but that has no impact on MySQL - they are totally unrelated
    programs.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  10. #9

    Default Re: Date display format

    ; Specify how datetime and datetim4 columns are returned
    ; On => Returns data converted to SQL server settings
    ; Off => Returns values as YYYY-MM-DD hh:mm:ss
    ;mssql.datetimeconvert = On

    This was copied from the php.ini file and is what I was refering to.

    erickia Guest

  11. #10

    Default Re: Date display format

    erickia wrote:
    > ; Specify how datetime and datetim4 columns are returned
    > ; On => Returns data converted to SQL server settings
    > ; Off => Returns values as YYYY-MM-DD hh:mm:ss
    > ;mssql.datetimeconvert = On
    >
    > This was copied from the php.ini file and is what I was refering to.
    Yes, it's exactly what I was talking about. Look at the last line you
    have copied:

    ;mssql.datetimeconvert = On

    It says *mssql*, not mysql. It's also in the [MSSQL] section of php.ini.
    The MySQL and MySQLi commands are much higher up, and contain no
    settings that affect the date.


    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  12. #11

    Default Re: Date display format

    SELECT column1, column2, DATE_FORMAT(date_column, '%M %D %Y')

    Let me see if I understand. I've already performed a query to retrieve the
    record I want. Now I should perform another query that will return just the
    particular date field within that record with formating set to how I want the
    field to display using the highlighted text above to replace the * in the
    query. If that is correct, can I do it in the form "SELECT
    senddate,DATE_FORMAT(senddate,'%M %D %Y') FROM table" IOW, I don't understand
    what "column1," "column2" or "date_column" stand for.


    erickia Guest

  13. #12

    Default Re: Date display format

    erickia wrote:
    > IOW, I don't understand
    > what "column1," "column2" or "date_column" stand for.
    They stand for the names of the columns in your table.

    Let's say you currently have a SQL query like this:

    SELECT * FROM myrecords

    Because you want to retrieve the date in a special format, you need to
    name each column separately, instead of using *.

    In your recordset dialog box, click the Advanced button. In the Database
    Items box at the bottom, expand Tables, and then the table you want to
    use. Highlight the first column you want to include in your recordset,
    and click SELECT. Do the same for every column you want to include.

    This will build a SQL query in the SQL field at the top. In the Advanced
    interface, Dreamweaver usually adds the name of the table to each
    column, so you'll end up with something like this:

    SELECT myrecords.name, myrecords.order, myrecords.senddate
    FROM myrecords

    Surround the senddate column with the DATE_FORMAT I gave you:

    SELECT myrecords.name, myrecords.order,
    DATE_FORMAT(myrecords.senddate,'%M %D %Y')
    FROM myrecords

    Make sure there is *no space* between DATE_FORMAT and the opening
    parenthesis. Your recordset will now contain the formatted date.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  14. #13

    Default Re: Date display format

    $query_Recordset1 = "SELECT
    City,Address1,DocumentPrice,Buyer,Seller,DATE_FORM AT(SaleDate,' %M %D %Y') FROM
    land WHERE compid = 9999";

    OK, this is the query, which seemed to work.

    <?php echo $row_Recordset1['SaleDate']; ?>

    And this was the code to display the date, which didn't work. Using "Live
    Data" to check the coding, I get an error saying "Undefined index SaleDate in
    C:\htdocs" etc. The other fields display fine.

    erickia Guest

  15. #14

    Default Re: Date display format

    I found the answer. Don't have to change the SELECT string afterall. Just had
    to use the following syntax for the formatting.

    <p><?php echo date(' F jS Y',strtotime($row_Recordset1['SaleDate'])); ?>

    erickia Guest

  16. #15

    Default Re: Date display format

    erickia wrote:
    > And this was the code to display the date, which didn't work. Using "Live
    > Data" to check the coding, I get an error saying "Undefined index SaleDate in
    > C:\htdocs" etc. The other fields display fine.
    Right, I see where the problem lies. You need to assign an alias to the
    SaleDate column like this:

    $query_Recordset1 = "SELECT
    City,Address1,DocumentPrice,Buyer,Seller,
    DATE_FORMAT(SaleDate,' %M %D %Y') AS SaleDate
    FROM land WHERE compid = 9999";

    That should now work. What happened was that MySQL was returning the
    SaleDate column with DATE_FORMAT as part of the column name. By adding
    "AS SaleDate", it will use the original name.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  17. #16

    Default Re: Date display format

    erickia wrote:
    > I found the answer. Don't have to change the SELECT string afterall. Just had
    > to use the following syntax for the formatting.
    >
    > <p><?php echo date(' F jS Y',strtotime($row_Recordset1['SaleDate'])); ?>
    Yes, that's a valid way of doing it, although getting MySQL to do it for
    you is more efficient. It's also useful to know how MySQL date and time
    functions work.

    --
    David Powers
    Author, "Foundation PHP 5 for Flash" (friends of ED)
    Co-author "PHP Web Development with DW MX 2004" (Apress)
    [url]http://computerbookshelf.com[/url]
    David Powers Guest

  18. #17

    Default Re: Date display format

    .oO(erickia)
    >I found the answer. Don't have to change the SELECT string afterall. Just had
    >to use the following syntax for the formatting.
    >
    > <p><?php echo date(' F jS Y',strtotime($row_Recordset1['SaleDate'])); ?>
    If a database is capable of returning formatted dates you should use it.
    It's easier, faster and more reliable. Additionally PHP uses Unix
    timestamps, which are restricted in range.

    Micha
    Michael Fesser Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139