I want to put this format data on my table: 2018-12-04T13:05:00-00:00
This should be done with a query:
$uPqr = $conn->query("UPDATE table SET dateModified = "the date goes here" WHERE id = 25");
I don't want to write the date on the query, i want to know if there's a function like NOW() or time() that do it automatically.
If you want the current time -- on the server -- then just use now():
$uPqr = $conn->query("UPDATE table SET dateModified = now() WHERE id = 25");
Related
I am using PHP with MySQL and would like to select rows that have a booking time within 2 hours from now. How do I compare what is in my database with the NOW() MySQL function?
I have columns pickupDate in the format yyyy-mm-dd and pickupTime in the format HH:mm (24-hour). I have tried creating a query with NOW() which returns the a 12-hour time as HH:mm:ss e.g. 2019-05-24 07:54:06 . I can't figure out how to format this to 19:54, or if I should use a different function instead.
For example, if the current date and time is 24/05/19 19:54:06, I would like to select rows between 19:54 and 21:54 on this date.
My table structure is:
referenceNo VARCHAR(100)
pickupDate DATE
pickupTime VARCHAR(100)
You need to create a DATETIME compatible value out of your pickupDate and pickupTime (which you can do by CONCATing them together), then you can compare that with a time range from NOW() to 2 hours later:
SELECT *
FROM yourtable
WHERE CONCAT(pickupDate, ' ', pickupTime) BETWEEN NOW() AND NOW() + INTERVAL 2 HOUR
Demo on dbfiddle
To add two hours in php
$hoursnow = date('H:i');
$timestamp = strtotime(date('H:i')) + 60*60*2;
$plusTwohours = date('H:i', $timestamp);
And $PlusTwohours using this variable frame the query like below
Sql Query:
$sqlQuery = 'select * from foodorder where pickupDate=DATE(NOW()) AND pickupTime>='.$hoursnow.' and pickupTime<='.$plusTwohours;
$result = mysql_query($sqlQuery);
variable $result will have the values of query
For Second Scenario: Adding hours to end of the day May 24 23:30:00
This should be handle by two different date for same column pickupDate
$d = new DateTime('2011-01-01 23:30:30');
$startDate = $d->format('Y-m-d H:i:s'); // For testing purpose assigned manually
$starttime = date('H:i');
// Here Process start, storing end date by adding two hours
$enddate1 = strtotime($startDate) + 60*60*2;
$enddate = date('Y-m-d', $enddate1); // Extracting date alone
$endtime = date('H:i', $enddate1); // Extracting time alone
Have to compare start and end date for column pickupDate, here is the query
$sqlQuery = "select * from foodorder where pickupDate>=DATE(".$startDate.") AND pickupDate<=DATE(".$enddate.") AND pickupTime>='".$starttime."' AND pickupTime<='".$endtime."'";
$result = mysql_query($sqlQuery);
I am creating a time series of intraday (1 minute interval) time series. I have the variables date YYYYMMDD and time HH:MM:SS and would like to create the datetime YYYYMMDDTHH:MM:SS (or whatever format is not too important).
When looking at the output (just sample dates):
Date Time Datetime
20000101 9:30:00 1960-01-01T09:30:00
20000101 9:31:00 2000-01-01T09:31:00
.
.
.
20000102 9:30:00 1960-01-01T09:30:00
20000102 9:31:00 2000-01-02T09:31:00
SO whenever time is 9:30:00 the concatenation via dhms(date, 0, 0, time) gives me the wrong value.
My code actually picks stock prices in certain interval from higher frequency data:
data xtemp2;
set _v_&tables;
by symbol date time;
format datetime e8601dt. itime rtime time12.;
if first.symbol = 1 or first.date = 1 then do;
/* Initialize time and price when new symbol or date starts; */
rtime = time;
iprice = bid;
oprice = ofr;
itime = &start_time;
datetime = time;
end;
if time >= itime then do;
output;
itime = itime + &interval_seconds;
do while(time >= itime);
output;
itime = itime + &interval_seconds;
end;
end;
rtime = time;
iprice = bid;
oprice = ofr;
datetime = dhms(date, 0,0,itime);
retain itime datetime iprice oprice;
run;
Is it something in my code? because looking at the distinct date and time variable shows the correct date.
I wanted to combine these because I have a time series for each stock and would like to match merge them which - if I understand correctly - requires one unique id that could be my datetime variable.
The issue seems to be with this piece of conditional logic:
if first.symbol = 1 or first.date = 1 then do;
This means that the first instance of those by groups will execute datetime = time; instead of datetime = dhms(date, 0,0,itime); (presuming time >= itime is true).
I suggest replacing datetime = time; with datetime = dhms(date, 0,0,itime); in the first instance.
I have to update table which have column data type as integer, but I have an input as a datetime. this is query that i hve writen
UPDATE T_SCH_ETAX_TEMP SET CURRTIME = UNIX_TIMESTAMP
(TIMEDIFF("(SELECT DATE_FORMAT(?,'%H:%i:%s') TIMEONLY)", "(SELECT
DATE_FORMAT(CURRENT_TIMESTAMP,'%H:%i:%s') TIMEONLY)"), LENGTHTIME =
UNIX_TIMESTAMP(TIMEDIFF("(SELECT DATE_FORMAT(?,'%H:%i:%s')
TIMEONLY)", "(SELECT DATE_FORMAT(CURRENT_TIMESTAMP,'%H:%i:%s')
TIMEONLY)")
any one can help how to convert timestamp result as an integer so I can update the table using SSIS
I could be wrong, please forgive me if I am, but you seem to want something simpler:
UPDATE T_SCH_ETAX_TEMP
SET CURRTIME = UNIX_TIMESTAMP(
TIMEDIFF(TIME(?),
TIME(CURRENT_TIMESTAMP))),
LENGTHTIME = UNIX_TIMESTAMP(
TIMEDIFF(TIME(?), TIME(CURRENT_TIMESTAMP)));
Which would only require 2 parameters ('ss');
If this is the case, in can be simplified to:
UPDATE T_SCH_ETAX_TEMP
SET CURRTIME = UNIX_TIMESTAMP(
TIMEDIFF(?,
CURRENT_TIMESTAMP)),
LENGTHTIME = UNIX_TIMESTAMP(
TIMEDIFF(?, CURRENT_TIMESTAMP));
if you pre-format your parameter strings
I have this few line of codes where I save the date from datetimepicker to my database column REMINDER.
myCommand.CommandText = "Update kup_table SET REMINDER = #reminder Where ID = #theIDD"
myCommand.Parameters.AddWithValue("#reminder", DateTimePicker1.Value.Date)
myCommand.Parameters.AddWithValue("#theIDD", theID)
myCommand.ExecuteNonQuery()
In my database, the date is saved in this format 2015-12-14 00:00:00 since the datatype is DATETIME.
How do I compare it with the date now? If the saved date and today date are a match, then a reminder will go off.
I have tried using this sql command but having still having trouble where the reminder is always zero. Thanks in advance.
myCommand.CommandText = "Select COUNT(*) from kup_table Where REMINDER BETWEEN DATE() AND DATEADD('d', 1, DATE())"
mySqlConn.Open()
Console.WriteLine("Connected.")
count = myCommand.ExecuteScalar()
MsgBox("You have " + count.ToString + " reminder(s).")
Select COUNT(*) from kup_table Where DATE(REMINDER) = DATE(NOW())
The DATE() function returns the date part of the datetime only. (e.g. 2015-12-14)
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date
I have a table called calendar with a column DateTo
This has format 2014-02-19T16:00:00 (varchar and can not be changed)
I would like to set time to 13:00
I've tried
UPDATE calendar
SET DateTo = (SUBSTRING(DateTo FROM 1 FOR 11) + '13:00')
WHERE SUBSTRING(DateFrom FROM 1 FOR 10) = '2014-02-19'
Thinking this would give me:
2014-02-19T13:00
but instead it returns 2027?
You can do as
update
calendar
set DateTo = concat(
substring_index(DateTo,'T',1),'T','13:00'
)
where substring_index(DateTo,'T',1) = '2014-02-19'
;
DEMO
As MatBailie suggested instead of
where substring_index(DateTo,'T',1) = '2014-02-19'
its better to use
WHERE DateTo LIKE '2014-02-19T%'
This will be significantly faster if there is an index on DateTo