Can't insert datetime to MySql [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have this weird thing when i get the date time: $date = date("Y-m-d H:i:s");
and try to insert it to a database, it will insert null. The column i insert it in is a datetime. It does not matter to what datatype i change the column it will still insert null.
I hope someone can help me!

Because the column is a datetime, in your query instead of
$sql = ".... datefield = '$date' ....";
do
$sql = ".... datefield = TIMESTAMP('$date') ....";
Obviously the .... represents whatever your sql is at that point.

Related

Check if Date is between two dates in mysql [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have a mysql record with the columns start_date and end_date. Now I have a date (as example 2017-08-03) and i want to ask if this date is between the start_date and end_date in my mysql table.
Is this possible?
Use between:
SELECT * FROM events
WHERE '2012-01-18' between start_date AND end_date
BTW: Take care of time part if start and end are datetime types
You can use this:
SELECT * FROM events
WHERE start_date<='2012-01-18'
AND end_date>='2012-01-18'
SELECT *
FROM `yourtable`
WHERE (your_found_date BETWEEN 'start_date' AND 'end_date')

Check when a information provided from sql changes in php [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I want to get a warning when a date is different like:
I have a while and wanted to when it reaches to a different date, it warns me
$hist=mysqli_query($db, "SELECT * from history");
while($his=mysqli_fetch_assoc($hist)){
If(certain_date != last_date){
echo certain_date;
}
}
Certain date and last date is the ones I wanna get
This is simply done like this
$hist=mysqli_query($db, "SELECT * from history");
$last_date = '';
while($his=mysqli_fetch_assoc($hist)){
If($his['ano'] != $last_date){
echo $his['ano'];
$last_date = $his['ano'];
}
}

pulling data out of mysql creating array with array structure [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a MySql database with three columns: skp, date and usr. For each skp and date pair there are several usr(s). Is there a query that will pull the data out with the following array structure:
array[i]['skp']
array[i]['date']
array[i]['usr'][j]
I'm wondering if somehow using a group by would work?
Use GROUP_CONCAT.
SELECT skp, date, GROUP_CONCAT('usr') AS usr
FROM yourTable
GROUP BY skp, date
Then when retrieving, you can split the usr column into an array.
$array = ();
while ($row = mysqli_fetch_assoc($result)) {
$row['usr'] = explode(',', $row['usr']);
$array[] = $row;
}

How to search string in MySQL [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to search number in my MySQL data. String is +310623212542 but the mysql row data is only 0623212542. How can i compare ? Please help i am new to the mysql
Use
In php
<?php
$search_text = substr('+310623212542',3);
mysqli_query("SELECT * FROM tbl WHERE search LIKE '%$search_text%'");
?>
or
in mysql
use SUBSTRING
SELECT * FROM tbl WHERE search = SUBSTRING('+310623212542' FROM 4)
Note: using substring in mysql impact performance issue, when large data present

Automatically edit row based on date [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am currently trying to create a script/function that should set a value to all items (eshop goods) old 15 days or older.
This script will be used as cron.
Date is stored in database as integer, but I don't exactly know how to approach the 15 days gap.
Could somebody help me out please?
Thank you.
You can try something like this
$integer_format = strtotime("-15 days");
$dateTime_format = date("Y-m-d h:i:s A T",$integer_format);
echo 'In integer format: '.$integer_format.'</br>'; //1403953190
echo 'In date time format: '.$dateTime_format.'</br>'; //2014-06-28 12:59:50 PM CEST

Categories