Can´t retrieve the date from MySQL

Max

I do an INSERT into mySQL database like this:

$sDate=date("Y-m-d h:i:s");
INSERT INTO tbl_1 (datum) VALUES ('$sDate')

And it'll do the INSERT But then when I try to find out the unique ID by selecting the date like this:

SELECT id AS nyPost FROM tbl_1 WHERE datum ='$sDate'

It will return nothing, not even an error message. The datum format is datetime. Please whats wrong? CODE:

    <?php
        $sDate=date("Y-m-d h:i:s");
        echo $sDate;
    If ($strNy) 
    {
        $_nyPrSQL="INSERT INTO begagnads (`anvId`, `tabort`, `datum`) VALUES ('8' , 'null', '$sDate')";

    //  echo  $_nyPrSQL;
        if (!mysqli_query($con,$_nyPrSQL)) 
        {die('Error: ' . mysqli_error($con));}
        else
        {
        echo "<br>1 record added";
        }

$result = mysqli_query($con,"SELECT id FROM begagnads WHERE DATE(datum) ='$sDate' ");

while($row = mysqli_fetch_array($result)) {
  echo $row['id'] . " " . $row['datum'];
  $nyPost= $row['id'];
  echo "<br>";
}
    ?>
Girish

MySql DATE() function Extracts the date part of the date or datetime expression expr.

mysql> SELECT DATE('2003-12-31 01:02:03');
        -> '2003-12-31'

If you want to find by DATE only

SELECT id FROM begagnads WHERE DATE(datum) = DATE('$sDate')

And if you find with date and time then no need DATE() function

SELECT id FROM begagnads WHERE datum = '$sDate'

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

how can i retrieve date from mysql database and subtract it with current date?

From Dev

Can't retrieve OUT parameters from stored procedures (MySQL)

From Dev

Can't retrieve OUT parameters from stored procedures (MySQL)

From Dev

how to save & retrieve a null date from mysql db using jdatechooser

From Dev

Java Retrieve date records in correct format from mysql

From Dev

How can I retrieve data from the database when the date > now()

From Dev

Retrieve the week number from a date

From Dev

Retrieve the date from a string path

From Dev

How can I usefully retrieve values from a mysql column in php?

From Dev

Data wasn't able to retrieve from the previous page (PHP and MYSQL)

From Java

Can't retrieve any data from database

From Dev

Can't retrieve files from hadoop hdfs

From Dev

Can't properly retrieve objects from NSMutableArray

From Dev

can't retrieve location from facebook users

From Dev

Can't retrieve $_POST value from URL

From Dev

Can't retrieve AJAX data from PHP

From Dev

Can't retrieve value from session

From Dev

Can't retrieve from double HashMap

From Dev

Can't retrieve data in table from json

From Dev

can't retrieve value from JSON results

From Dev

CloudKit - Can't retrieve the data from iCloud

From Dev

Can't retrieve text value from QLineEdit

From Dev

Can't retrieve data from SharedPreferences?

From Dev

Can't retrieve values from a ManyToManyField in Django

From Dev

Can't retrieve data from controller AngularJS

From Dev

mysql if there is a duplicate retrieve the most recent date of it

From Dev

PHP Mysql PDO retrieve records by date range

From Dev

retrieve equal value from mysql

From Dev

MySQL retrieve results between 2 dates without time factor doesn't output results of exact date

Related Related

  1. 1

    how can i retrieve date from mysql database and subtract it with current date?

  2. 2

    Can't retrieve OUT parameters from stored procedures (MySQL)

  3. 3

    Can't retrieve OUT parameters from stored procedures (MySQL)

  4. 4

    how to save & retrieve a null date from mysql db using jdatechooser

  5. 5

    Java Retrieve date records in correct format from mysql

  6. 6

    How can I retrieve data from the database when the date > now()

  7. 7

    Retrieve the week number from a date

  8. 8

    Retrieve the date from a string path

  9. 9

    How can I usefully retrieve values from a mysql column in php?

  10. 10

    Data wasn't able to retrieve from the previous page (PHP and MYSQL)

  11. 11

    Can't retrieve any data from database

  12. 12

    Can't retrieve files from hadoop hdfs

  13. 13

    Can't properly retrieve objects from NSMutableArray

  14. 14

    can't retrieve location from facebook users

  15. 15

    Can't retrieve $_POST value from URL

  16. 16

    Can't retrieve AJAX data from PHP

  17. 17

    Can't retrieve value from session

  18. 18

    Can't retrieve from double HashMap

  19. 19

    Can't retrieve data in table from json

  20. 20

    can't retrieve value from JSON results

  21. 21

    CloudKit - Can't retrieve the data from iCloud

  22. 22

    Can't retrieve text value from QLineEdit

  23. 23

    Can't retrieve data from SharedPreferences?

  24. 24

    Can't retrieve values from a ManyToManyField in Django

  25. 25

    Can't retrieve data from controller AngularJS

  26. 26

    mysql if there is a duplicate retrieve the most recent date of it

  27. 27

    PHP Mysql PDO retrieve records by date range

  28. 28

    retrieve equal value from mysql

  29. 29

    MySQL retrieve results between 2 dates without time factor doesn't output results of exact date

HotTag

Archive