Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi guys,
I have a question as follows. Original I have the date variable, how to get 4 months later for each record as the new variable date1?
I asked this question before, but the issue is that now the format of the date contains time. Anyone could help? Thanks!
Original table:
ID | date | score |
---|---|---|
1 | 2009-12-31 12:00:00 AM | 80 |
2 | 2011-06-30 12:00:00 AM | 50 |
Final table
ID | date1 | date | score |
---|---|---|---|
1 | 04/2010 | 2009-12-31 12:00:00 AM | 80 |
2 | 10/2011 | 2011-06-30 12:00:00 AM | 50 |
Load
Date(AddMonths(Date#(date, 'YYYY-MM-DD hh:mm:ss TT'),4), 'MM/YYYY') as date1
Hi, I tried this but it still doesn't work...not sure why...
Try this
TT:
Load *,Date(AddMonths(Date(SubField(date,' ',1)),4),'MM/YYYY') as Date1;
Load * Inline [
ID, date, score,
1, 2009-12-31 12:00:00 AM, 80
2, 2011-06-30 12:00:00 AM, 50
];
It should work if your date field data format is similar. Else, try to share your sample app with sample data.
Convert new date field like
Date(AddMonths(Date#(date,'YYYY-MM-DD hh:mm:ss TT'),4),'MM/YYYY') as newDate
See the sample example for this
LOAD date,ID,score, Date(AddMonths(Date(Left(date,10)),4),'MM/YYYY') as NewDate;
LOAD * Inline
[
ID, date, score
1, 2009-12-31 12:00:00 AM, 80
2, 2011-06-30 12:00:00 AM, 50
];
Regards
If having problem then create a new field like this also
Date(AddMonths(Date(Left(date,10)),4),'MM/YYYY') as NewDate;
Like the others have said try