I have written the following code to update a datetime field with today's datetime:
User.update( {'email': email } , {'resetpwddateExpire' : new Date() })
The date part is updating correctly, but the time part is not. For example:
if resetpwddateExpire starts as 2/14/2014 8:08:52 AM
after the update, resetpwddateExpire is now 2/7/2014 9:08:52 AM
but it should be 2/7/2014 3:08:52 PM
I assume you are using Mongoose. It seems to me that when the document was created, the resetpwddateExpire field was set to sometime in future. And when you update it, it becomes today's date which is 7th Feb 2014.
Perhaps using $set operator would help.
var oneWeek = 7 * 24 * 60 * 60 * 1000;
User.update( {'email': email } , {'$set': {'resetpwddateExpire' : Date.now() + oneWeek}}, function(...){});
Related
I have a database from a custom application.
The values in the database for a date is 44416.254005, and the application that uses this database resolves that number to the following date 8/8/2021 6:05:46 AM.
Another example is 44416.268113 to 8/8/2021 6:26:05 AM.
ex. 44328.93713 = 5/12/2021 10:29:28 PM
I have an old backup of this database and need to figure out how the conversions are made?
This looks like the an Excel format for a date. If so, you can convert to seconds and add to 1899-12-31:
select timestamp '1899-12-31 00:00:00' + (44416.268113 * 60 * 60 * 24) second
import datetime
def xldate_to_datetime(xldate):
start = datetime.datetime(1899, 12, 30)
delta = datetime.timedelta(days=xldate)
return start + delta
I have a column named ClientMigrated of the format 7/23/2019 7:56:45 AM
I have a query that is run within a macro to count the rows where the date portion of ClientMigrated is the current day.
UPDATE Tracking SET Tracking.UserMailboxesMigrated =
DCount("ClientMigrated","[Mailbox Status]","ClientMigrated=Date()")
WHERE (((Tracking.ReportingDate)=Date()));
The query returns nothing because ClientMigrated contains the timestamp part which does not equate to the date.
I've tried to wrap ClientMigrated in a format function so that it compares to Date():
format(ClientMigrated, "dd/mm/yyyy")=Date()
it seems is not acceptable syntax within DCount.
Suggestions to get around this is appreciated.
Consider DATEVALUE to extract the date portion of a date/time field:
UPDATE Tracking t
SET t.UserMailboxesMigrated = DCount("ClientMigrated",
"[Mailbox Status]",
"DATEVALUE(NZ(ClientMigrated, ""1900-01-01"")) = Date()")
WHERE (DATEVALUE(t.ReportingDate) = Date());
Nz should return a date value, not a string, for Null:
UPDATE Tracking t
SET t.UserMailboxesMigrated = DCount("ClientMigrated",
"[Mailbox Status]",
"DateValue(Nz(ClientMigrated, #00:00:00#)) = Date()")
WHERE DateValue(t.ReportingDate) = Date();
You need to utilize the FORMAT function
Assuming that you are using the default value for DATE(), you should be able to use:
UPDATE Tracking
SET Tracking.UserMailboxesMigrated =
DCount("ClientMigrated", "[Mailbox Status]", "ClientMigrated=Date()")
WHERE (((Format(Tracking.ReportingDate, "dd/mm/yyyy"))=Date()));
To use an index onClientMigratedyou should check the datetime field for being same or greater than today (Date()) and smaller than tomorrow (DateAdd(""d"", 1, Date()). The""escapes the double-quote for theDateAddinterval-parameter nested in theDCountcriteria string.
UPDATE Tracking
SET UserMailboxesMigrated = DCount("ClientMigrated",
"[Mailbox Status]",
"ClientMigrated >= Date() AND ClientMigrated < DateAdd(""d"", 1, Date())
WHERE ReportingDate = Date();
ReportingDateis a date not a datetime? If datetime, use same pattern, but you must not escapeDateAdddouble-quotes.
I have a table invoices with this fields:
invDate -> a date field
invTime -> a time field
I need to do querys like
SELECT top 10 * from invoices WHERE DATETIME(invDate+invTime)
BETWEEN DATETIME('2013-12-17 17:58') AND DATETIME()
or something like that. I don't know how to concatenate the invDate and invTime to create a datetime field. The only thing that i could do is this horribly thing:
DATETIME( YEAR(invDate), MONTH(invDate), DAY(invDate), 17, 52 ) AS MyDatetime
Couldn't even get hour and time with hour(invTime) and minute(invTime):
DATETIME( YEAR(invDate), MONTH(invDate), DAY(invDate),
HOUR(invTime), MINUTE(invTime) ) AS MyDatetime
I'm doing the querys throught the VFP Odbc Driver via PHP.
You were pretty close. If the value coming from PHP is not of a date/time, how could VFP interpret it properly. VFP also has a function CTOT() (character to time), and expects it in the format of 'yyyy-mm-ddThh:MM:ss??'
yyyy = 4 digit year
mm = 1 OR 2 digit month
dd = 1 OR 2 digit day
T -- literally the letter "T"
hh = 1 OR 2 digit hour (but typical is 2 anyhow)
MM = 1 or 2 digit minute (but typical is 2)
ss = 1 or 2 digit for seconds -- not required
?? = "AM" or "PM" if you wanted to explicitly provide that vs 24 hour clock
The MM and ss are optional, so if you finished with "T1" would be 1:00:00am
Now, to finish your query.
WHERE DATETIME(invDate+invTime)
BETWEEN DATETIME('2013-12-17 17:58') AND DATETIME()
Since this appears to be querying all invoices between a given date/time and NOW (via DateTime()), you don't even need between, you can do
WHERE YourTable.Column > CTOT( '2013-12-17T17:58')
If you specifically DID have a date/time range to consider, THEN you could do something like
WHERE YourTable.Column BETWEEN CTOT( '2013-12-05T10:00') AND CTOT( '2013-12-14T11:58')
PROBLEMS WITH your DATE() and TIME() implementations
The problem is Date() is a function to either return current date, or create based on y/m/d provided such as date( 2013, 12, 7 ). If you are passing a string, use CTOD( 'mm/dd/yyyy' ) such as CTOD( 12, 7, 2013 ).
As for the TIME() function that just expects a number and is of no use for you. From the OleDbProvider, your best bet is to just create a php function that builds a single string in the CTOT() format I've described and pass to the php function the date and time fields. Then use that as your "CTOT( functionReturnResult )"
To add a Date and a Time Field together you will need to convert them both to a same datatype 1st and than just simply add them together something like this....
DECLARE #D DATE = '2013-12-17'
DECLARE #T TIME = '17:58:00'
SELECT CAST(#D AS DATETIME) + CAST(#T AS DATETIME)
Result
2013-12-17 17:58:00.000
Your Query
SELECT top 10 *
from invoices
WHERE CAST(invDate AS DATETIME) + CAST(invTime AS DATETIME)
BETWEEN '20131217 17:58:00.000' AND GETDATE()
how to show date in expirydate column which is 5 time more of the original date.
i.e. i have a column name created and have a deafult date(7/19/2023) but in expiry date column i want to show a date like (7/24/2013) always when i save the expiry date will be 5 more to the original date?
public function rules(){
return array(
array('title','required'),
array('jobid,notes,companyid,createdon,expirydate','safe'),
array('createdon','default',
'value'=>new CDbExpression('NOW()'),
'setOnEmpty'=>false,'on'=>'update'),
array('createdon,expirydate','default',
'value'=>new CDbExpression('NOW()'),
'setOnEmpty'=>false,'on'=>'insert')
);
}
You can use strtotime to calculate expirydate:
$time = strtotime('+5 days', strtotime($model->createdon));
$model->expirydate = date('m/d/Y', $time );
How can I update only the time in an already existing DateTime field in MySQL? I want the date to stay the same.
Try this:
UPDATE yourtable
SET yourcolumn = concat(date(yourcolumn), ' 21:00:00')
WHERE Id = yourid;
Try this:
UPDATE t1 SET DateTimeField = CONCAT(DATE(DateTimeField),' 12:34:56');
UPDATE myTable
SET myDateTime = ADDTIME(DATE(myDateTime), #myTimeSpan)
WHERE id = #id;
Documented on MySQl date functions MySQL docs
I have solved in this way:
UPDATE table
SET myDateTime = CONCAT_WS(' ',DATE(myDateTime), CURTIME())
WHERE id = #id;
Obviously you should change CURTIME() with your desired time.
UPDATE myTable
SET myDateTime = ADDTIME(myDateTime, #myTimeSpan)
WHERE id = #id;
For exact syntax of function, see this.
Try this:
UPDATE sms
SET entry_period_end_date= entry_period_end_date+INTERVAL 6 Hour
WHERE TIME(entry_period_end_date) = '06:00:00';
UPDATE `table`
SET time = ADDTIME(time, INTERVAL 13 Hour);
Well, exactly what you are asking for is not possible. The date and time components can't be updated separately, so you have to calculate the new DateTime value from the existing one so that you can replace the whole value.
MySQL DEV page shows functions like subtime and difftime
A sample code to back the time all posts in 3 hours is above:
UPDATE tablepost SET datepost = SUBTIME( datepost , '0 3:0:0' );
Note that values 0 dont alter the respective field. Take care this code, use select first to test these function.
Reference: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_subtime
Asuming you have a DATE field and TIME field and want to inject the time into the date, try this:
UPDATE mytable
SET mydatefield = ADDTIME( DATE_FORMAT(mydatefield,'%Y-%m-%d 00:00:00'), mydatefield)
WHERE myid = ...
I used ADDTIME in the following way
Earlier in my cloud server, the DateTime was set to UTC but after changing the DateTime to Asia/Kolkata ie UTC 5:30 I wanted the same to reflect in my database tables.
I wanted to update the created_at and updated_at column by 5 hours 30 minutes. I did the following
To update all the rows of the table
UPDATE
products
SET
created_at = ADDTIME(created_at, '5:30:0'),
updated_at = ADDTIME(updated_at, '5:30:0')
You can omit the WHERE condition if you want to update all the records, but since my new records were updated with proper values. So only my rows below id less than 2500 must be updated
UPDATE
products
SET
created_at = ADDTIME(created_at, '5:30:0'),
updated_at = ADDTIME(updated_at, '5:30:0')
WHERE
id < 2500;
This what helped me. I convert time to minutes firstly: 150 for 2:30 am.
UPDATE lesson SET starts_at = DATE_ADD(Date(starts_at), INTERVAL 150 MINUTE)
Minutes are enough accurate for me, though you can use other units: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_date-add