I have a datetime column in lotus notes which has value like 01/02/2019 01:01:01 PM.
I need to export the data into csv file in the below format:
2019-01-02 13:01:01.000
Tried changing the column properties in the view but while exporting the data is changed to 01/02/2019 01:01:01.
Here AM/PM is getting ignored.
Please suggest a way to do this properly.
Thanks in advance.
Use this formula in your view column, where DateField is the field with date.
year := #Text(#Year(DateField));
month := #Right("0" + #Text(#Month(DateField)) ; 2);
day := #Right("0" + #Text(#Day(DateField)) ; 2);
hour := #Right("0" + #Text(#Hour(DateField)) ; 2);
minute := #Right("0" + #Text(#Minute(DateField)) ; 2);
second := #Right("0" + #Text(#Second(DateField)) ; 2);
year + "-" + month + "-" + day + " " +
hour + ":" + minute + ":" + second + ".000"
Those #Right functions will pad your values with zeroes when needed.
Related
I am using condition below to show data for current month only/previous month(if its new month started).
let's say today is 3rd june so it should only give 1st an 2nd data,if its 10 it should give data from 1 to 9th,similarly it should be like this until month end but when there will be 1st of next month it should give data from previous month. the conditions I am using are giving blank data on every 1st. . Here is the condition I am using:
where Datestarted between CURRENT_DATE - EXTRACT( DAY FROM CURRENT_DATE) + 1
AND
ADD_MONTHS(( CURRENT_DATE - EXTRACT (DAY FROM CURRENT_DATE) + 1), 1) - 1
You probably need to base your calculation on yesterday, not today:
where Datestarted between (CURRENT_DATE-1) - EXTRACT( DAY FROM CURRENT_DATE-1) + 1
AND
CURRENT_DATE-1
Do you maybe mean previous month to date?
Try this:
select
calendar_date
from
sys_calendar.calendar
where
calendar_date between cast((ADD_MONTHS(CURRENT_DATE,-1)/100*100)+1 as DATE) and
add_months(current_date,-1)-1
EDIT: Based on your comments, let's try this:
SELECT
calendar_date
FROM
sys_calendar.CALENDAR
WHERE
(EXTRACT(DAY FROM CURRENT_DATE) = 1 --previous month
AND
Calendar_Date BETWEEN CAST((ADD_MONTHS(CURRENT_DATE, - 1)/100 * 100) + 1 AS DATE)
AND CURRENT_DATE - EXTRACT(DAY FROM CURRENT_DATE))
OR--current mtd
(
Calendar_Date BETWEEN CAST((CURRENT_DATE / 100 * 100) + 1 AS DATE)
AND CURRENT_DATE - 1
)
ORDER BY calendar_date
I have two date prompts FromDate and Todate in Cognos. FromDate should always be Prior Week first Day (i.e, Monday) and ToDate should be last day of that week(i.e., Sunday). Any help will be appreciated. thanks
FromDate
The following expression will return Monday of the previous week:
_add_days(current_date, (-1 * _day_of_week(current_date,2)) - 7)
ToDate
From there you can get the Sunday following the FromDate value:
_add_days([FromDate],6)
The only issue is what range you want when the report is run on Monday. Using the above expressions the report will go back an extra week when run on Monday. To get around this you can test for Monday and change the FromDate expression accordingly:
CASE _day_of_week(current_date,1)
WHEN 1 THEN _add_days(current_date, -1 * _day_of_week(current_date,2))
ELSE _add_days(current_date, (-1 * _day_of_week(current_date,2)) - 7)
END
When run on a Monday using this expression the previous Monday FromDate will be the previous Monday and ToDate will be the Sunday just before the current date.
The only way to dynamically set prompt defaults for date prompts is to use JavaScript. Thankfully, Cognos has provided a fully-supported JavaScript prompt API in versions 10.2.1 and above.
In order to reference prompt objects via the Cognos JavaScript API you have to give the prompt a unique name. For the following code I've assumed your "from date" prompt has been named "FromDate" and the "to date" prompt has been named "ToDate".
Insert the following code into a new HTML object. Make sure the HTML object appears after any prompt objects.
<script>
var report = cognos.Report.getReport('_THIS_');
var FromDate = report.prompt.getControlByName('FromDate');
var ToDate = report.prompt.getControlByName('ToDate');
var today = new Date();
var fromdate = new Date();
var todate = new Date();
fromdate.setDate(today.getDate() - (today.getDay() + 6));
todate.setDate(today.getDate() - today.getDay());
var fromdatestring = fromdate.getFullYear() + '-' + ("0" + (fromdate.getMonth() + 1)).slice(-2) + '-' + ("0" + fromdate.getDate()).slice(-2);
var todatestring = todate.getFullYear() + '-' + ("0" + (todate.getMonth() + 1)).slice(-2) + '-' + ("0" + todate.getDate()).slice(-2);
FromDate.addValues([{'use':fromdatestring}]);
ToDate.addValues([{'use':todatestring}]);
</script>
I'd like to subtract 5 minutes from DateTime.now() May I know how I can do this?
Thanks!
addMinutes()
It has add in it's name but nobody says you can't pass a negative number.
DateTime dt = System.now();
DateTime earlier = dt.addMinutes(-5);
DateTime fullHour = dt.addMinutes( -dt.minute() ).addSeconds( -dt.second() );
System.debug(dt + '\t' + earlier + '\t' + fullHour);
2014-01-11 08:40:13 2014-01-11 08:35:13 2014-01-11 08:00:00
Just subtract time in days (Double format) from DateTime.now() as follows:
i.e. 5 (minutes) = 5 / 1440 (days)
DateTime dt = DateTime.now() - Double.valueOf(5) / 1440;
How can I convert an int value (ie: 1800) which represents minutes into a value that looks like this: dd:hh:mm (days:hours:minutes).
So 1800 should be converted into 1:06:00 (1 day 6 hours 0 minutes).
In a stored procedure I have this:
SELECT
Record_ID, Project_ID, Ticket_ID, WO_Type, DC, Title, Device_Quantity,
Total/1440 as Total,
((Total - Elapsed) - DATEDIFF(mi, Record_Time, getdate())) as FinalTimeLeft,
Completed
FROM Record
How would I implement the casting into the SP? Above FinalTimeLeft=1800
How about this example - it does hours, minutes and seconds but it should be easy to modify for days, hours and minutes:
SELECT
CAST(mins / 3600 AS VARCHAR) + ':' +
RIGHT('0' + CAST((mins % 3600) / 60 AS VARCHAR), 2) + ':' +
RIGHT('0' + CAST(mins % 60 AS VARCHAR), 2)
FROM
(SELECT 1800 AS mins) a
EDIT: Included your stored procedure with my code amended for day, hour and minute:
SELECT
*
,CAST(FinalTimeLeft / 1440 AS VARCHAR) + ':' +
RIGHT('0' + CAST((FinalTimeLeft / 60) % 24 AS VARCHAR), 2) + ':' +
RIGHT('0' + CAST(FinalTimeLeft % 60 AS VARCHAR), 2) AS duration
FROM (
SELECT
Record_ID
,Project_ID
,Ticket_ID
,WO_Type
,DC
,Title
,Device_Quantity
,Total/1440 as Total
,((Total-Elapsed)-DATEDIFF(mi,Record_Time,getdate())) as FinalTimeLeft
,Completed
FROM record) a
im looking for mathematical formulas to add and subtract months to/from a date. i only need to know the year and month, therefor days can be ignored.
this is the adding months pseudo code i came up with:
OldYear = 2012 // current year
OldMonth = 3 // current month
AddMonths = 0 // the months to be added
FooBar = OldMonth + AddMonths
NewYear = OldYear + FooBar / 12
NewMonth = FooBar % 12
IF NewMonth = 0
NewYear = NewYear - 1
NewMonth = 12
END IF
// set AddMonths to 0 and the result will be 2012.03
// set AddMonths to 6 and the result will be 2012.09
// set AddMonths to 9 and the result will be 2012.12
// set AddMonths to 11 and the result will be 2013.02
// set AddMonths to 23 and the result will be 2014.02
// set AddMonths to 38 and the result will be 2015.05
and it works really great, but is there an even better way? i dont really like the need for the IF NewMonth = 0 readjustments.
but my actual problem is, that i couldnt come up with a counterpart formula to substract months. i tried various things, but everything failed and its driving me insane. so any help would be much appreciated!
It is a combination of my comment in #Matt's answer, and answer of #Matt
The formula can be greatly reduced if you adopt a 0-based month scheme.
pseudocode:
year = 2012; // year 2012
month = 6; // July (NOT June)
monthToAdd = -20; // +ve/-ve means add/subtract
resultYear = (year * 12 + month + monthToAdd) /12;
resultMonth = (year * 12 + month + monthToAdd) mod 12;
// resultYear == 2010
// resultMonth == 10 , which means November
Edit: The original answer above assumed a zero-based month scheme, which seem being overlooked by some people. To avoid confusion, we can of course use more intuitive 1-based month scheme, and do the 0-base conversion during calculation (though it make the calculation slightly messier):
year = 2012; // year 2012
month = 7; // July
monthToAdd = -20; // +ve/-ve means add/subtract
resultYear = (year * 12 + (month - 1) + monthToAdd) /12;
resultMonth = ((year * 12 + (month - 1) + monthToAdd) mod 12) + 1
// resultYear == 2010
// resultMonth == 11 , which means November
One possible solution would be to multiply OldYear by 12 (thus converting it to months), adding or subtracting AddMonths or SubMonths, respectively, and then converting back to NewYear and NewMonth by using integer and modular division (depending on your programming language, you may be able to simplify this).
Full credit to Adrian Shum for building the main logic but I think there is a edge case which the code is not 100% accurate for cases where we go back the same number of months as the month we are in. For example, if we are in March and we go back 3 months we should end up at Dec (Feb, Jan and Dec) .
here is the modified version:
year = 2020;
month = 4;
monthToAdd = -1;
resultYear = (year * 12 + month + monthToAdd) /12;
resultMonth = (year * 12 + month + monthToAdd) % 12;
if month+monthToAdd == 0:
resultMonth=12
elif (abs(monthToAdd)%month)==0:
resultMonth=month
print(resultMonth)
print(resultYear)