Results 1 to 1 of 1

Thread: Using PHP to get dayname() in MySQL?

  1. #1
    Join Date
    Jun 2012
    FL, USA

    Using PHP to get dayname() in MySQL?

    I use the following code to try and return the name of the day for a given date by a MySQL query...and it don't work.

    It works when I do the MySQL query directly but not with PHP. Please consider:

    (I replaced the MySQL host, username, database and pass here-- but I KNOW they are correct in my code)

    <title>Test the date</title>
    <form action="<?php $_SERVER[PHP_SELF] ?>" method="POST">
    Type the date in YYYY-MM-DD format:
    <input type="text" name="date">
    <input type="submit" value="get info">
    $mysqlconn = mysql_connect("myhost", "myusername", "mypass");
    mysql_select_db("mydatabase", $mysqlconn);
    if (!isset($_POST[date])) {
      print "Enter a date...";
    } else {
      $date = $_POST[date];
      print "Info for $date:";
      print "<br />";
      $dayname = "SELECT dayname('$date')";
      print "The day of week of this date is: ";
      $daynamequery = mysql_query($dayname, $mysqlconn);
    ...Do I need to specify a database in my query, e.g.

    $dayname = "SELECT dayname('$date') FROM 'database'"; ???

    Please note I also know that $date is in the correct format for the mysql query YYYY-MM-DD.

    Edit: here is the link where the script is run: http://captainscall.site11.com/page_...estthedate.php

    Last edited by captainscall; 07-01-2012 at 02:36 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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