how to show date in expirydate column - yii

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 );

Related

Convert string to datetime in cosmos db

In my cosmos db a date field is stored as string like this
{
"ValidationWeekStartDay": "27-Apr-2020"
}
I have to write a query to extract all documents whose ValidationWeekStartDay is greater than current date. How can I achieve this in cosmos db query?
Select * from c wher c.ValidationWeekStartDay > GetCurrentDateTime ()
this does not give me correct result.
This is the problem with date format, the documents you are storing is in format 'dd-MMM-yyyy' while GetCurrentDateTime() function gets the date in format 'yyyy-mm-dd....'. So when you run the above query, comparison like below happens:
'27-Apr-2020' > '2020-08-17'
It compares the characters one by one and first 2 characters of first value becomes greater than second value. For testing purpose, anything above date 20 will be returned by your query irrespective of any month.
There are 2 ways to resolve this.
Store the date in same format as GetCurrentDateTime() function.
Create a udf like below. You can create your own udf, this is just a sample one based on date format.(pardon the formatting, you can copy and run it as it is)
function formatdatetime(datetime){ datetime = datetime.substring(7,11) + '-' + datetime.substring(3,6) + '-' + datetime.substring(0,2); datetime = datetime.replace('Jan','01'); datetime = datetime.replace('Feb','02'); datetime = datetime.replace('Mar','03'); datetime = datetime.replace('Apr','04'); datetime = datetime.replace('May','05'); datetime = datetime.replace('Jun','06'); datetime = datetime.replace('Jul','07'); datetime = datetime.replace('Aug','08'); datetime = datetime.replace('Sep','09'); datetime = datetime.replace('Oct','10'); datetime = datetime.replace('Nov','11'); datetime = datetime.replace('Dec','12'); return datetime; }
And then use the below query:
select c.stdDates as stdDates from c Where udf.formatdatetime(c.stdDates) > GetCurrentDateTime ()

SQL Update Query: Counting records with current date

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.

Query to retreive data having Data = '1753/01/01'

I want to retrieve those records which have Data <= paramdate and also those records which have Date = '1753/01/01'
Thanks
you could use DATEDIFF
DATEDIFF will return different time, day, month, pr year, based what you want to compare.
Example :
`DATEDIFF (DAY, '01/01/2017', '02/01/2017')`
This will return 1, as the comparation is the day.
Note : datediff also could return negative value, as the position which is higher. Example :
'DATEDIFF (DAY, '02/01/2017', '01/01/2017')'
will return -1
When you want to get the data that the date and the format are specified , you could use CONVERT to convert it to your formatted date and compare it like usual
Example :
WHERE CONVERT(VARCHAR, '2017/01/01', 103) = '01/01/2017'

Oracle SQL Between Date, Except Some Month

I've got a query which basically get information concerning the last 2 years from the current Date.
DateTime jodaCurrentDate = new DateTime();
DateTimeFormatter formatter = DateTimeFormat.forPattern("YYYY-MM-dd HH:mm");
String startingDate = formatter.print(jodaCurrentDate.minusYears(2));
String endingDate = formatter.print(jodaCurrentDate);
"DATE BETWEEN TO_DATE (\'"+ startingDate +"\',\'YYYY-MM-DD HH24:MI\') AND " +
"TO_DATE (\'"+ endingDate +"\',\'YYYY-MM-DD HH24:MI\')";
Is it possible to retrieve only for some particular months (01-02-03-10-11-12) for example?
This where clause filters for a date between two dates and also includes a filter on month. Replace some_date with your date column.
where some_date between to_date('01/01/2015','MM/DD/YYYY') and to_date('12/31/2015','MM/DD/YYYY')
and extract(month from some_date) in (1, 2, 3, 10, 11, 12);

Mongodb update datetime field

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(...){});