How to convert IST to dd-mm-yyyy fomat - date

I want date in dd-mmm-yyyy format..I'm getting as {dayOfYear: 106, dayOfMonth: 16, dayOfWeek: 2, era: 1, year: 2019, …}
I tried datepipe but its throwing error that 'Unable to convert "[object Object]" into a date' for pipe 'DatePipe'.
item.executionDate= this.datepipe.transform(item.executionDate , 'yyyy-MM-dd');

Related

Convert String to Date in Big Query error

I have a string field that is being pulled from a table and I'm trying to cast that as a date in a view I created. I keep getting an error when trying to Cast as a date though. The format of the field looks like this:
July 19, 2020 or
August 8, 2020 etc..
I get an error that states
"Failed to parse input string "July 19, 2020"
or one of the other dates in the data when trying to use DATE_Parse. Or I get
"Invalid Date:August 8, 2020"
if I try to use the CAST function.
Below is my query when trying to CAST the date:
select
noteattributes.value.name as name_type, noteattributes.value.value as name_value, CAST(noteattributes.value.value as DATE) as DATE_TEST, order_number
from test.orders,
unnest(note_attributes) as noteattributes
where noteattributes.value.name = 'Pickup-Date'
Convert String to Date
Below is for BigQuery Standard SQL
You should use PARSE_DATE instead of CAST as in below example
PARSE_DATE('%B %d, %Y', date_as_string)
You can test, play with this using example below
#standardSQL
WITH `project.dataset.table` AS (
SELECT 'July 19, 2020' date_as_string UNION ALL
SELECT 'August 8, 2020'
)
SELECT PARSE_DATE('%B %d, %Y', date_as_string) AS date_as_date
FROM `project.dataset.table`
with output
Row date_as_date
1 2020-07-19
2 2020-08-08

Date format does not work in R

This is my date column which is on my dateframe:
data <- data.frame(year_month = c("2015-01-01", "2015-02-01", "2015-03-01", "2015-04-01", "2015-05-01", "2015-06-01"))
class(data$year_month)
[1] "factor"
I tried:
data$year_month1<-as.Date(as.factor(data$year_month), format="%b %Y")
I want:
" Jan 2015", "Feb 2015", "Mar 2015", "Apr 2015", "May 2015", "Jun 2105"
What happens:
My column on data$year_month1 comes Empty.
I tried quite a few solutions that I found here but the format does not change at all or it comes empty.
Help, please>
format(as.Date(data$year_month), format="%b %Y")
#first convert to Date, without as.factor (why did you do that?)
#then convert it to character as you want it, with format()

Date format for oData.create

I have a create with filter oEntry:
oEntry.Budat = new Date();
oDataModel.create('/DeliveryCompleteSet', oEntry, null, function(oData){
MessageToast.show(oData.Text,{
duration: 5000,
width: "100em",
});
oEntry contains one date field and it gives me an error "invalid date" when I execute the create. What format does the field have to be?
Check here
Edm.DateTime Represents date and time with values ranging from 12:00:00 midnight, January 1, 1753 A.D. through 11:59:59 P.M, December
9999 A.D.

Why is Calendar.date(from: DateComponents) adding time?

I create an instance of DateComponents using the following code:
let dateComponents = DateComponents(
calendar: .current,
timeZone: Calendar.current.timeZone,
era: nil,
year: nil,
month: nil,
day: nil,
hour: 9,
minute: 0,
second: 0,
nanosecond: 0,
weekday: 2,
weekdayOrdinal: nil,
quarter: nil,
weekOfMonth: nil,
weekOfYear: nil,
yearForWeekOfYear: nil)
I then print the dateComponents object and get the following (expected) output:
calendar: gregorian (current) timeZone: Europe/London (current) hour: 9 minute: 0 second: 0 nanosecond: 0 weekday: 2 isLeapMonth: false
Immediately following this, I print the date created using the following code:
print(Calendar.current.date(from: dateComponents)!)
To my great dismay and thorough unhappiness, the following is outputted:
0001-01-01 09:01:15 +0000
The date(from: dateComponents) function appears to have added just over a minute to the dateComponents before creating a date from them.
Thanks for any help in advance.
NSDate has some strange and undocumented behaviors for ancient dates. The change seems to have happened around 1895:
for year in 1890..<1900 {
// January 1 of each year # 9AM
let dateComponents = DateComponents(
calendar: .current,
timeZone: Calendar.current.timeZone,
year: year,
month: 1,
day: 1,
hour: 9)
if dateComponents.isValidDate {
print(dateComponents.date!)
}
}
My calendar is Gregorian and timezone is EDT (UTC -0500). This is the output:
1890-01-01 14:17:32 +0000
1891-01-01 14:17:32 +0000
1892-01-01 14:17:32 +0000
1893-01-01 14:17:32 +0000
1894-01-01 14:17:32 +0000 // not correct
1895-01-01 14:00:00 +0000 // correct
1896-01-01 14:00:00 +0000
1897-01-01 14:00:00 +0000
1898-01-01 14:00:00 +0000
1899-01-01 14:00:00 +0000
So for the years prior to 1895, Apple somehow added 17 minutes and 32 second to my time. You got a different offset, which is likely due your locale settings.
I couldn't find anything historical event about the Gregorian calendar in 1895. This question mentions that Britain started to switch over to GMT and the Greenwich Observatory started adjusting date/time standards across the British Isles in the 1890s so that may have accounted for this offset. Perhaps someone can delve into the source code for Date / NSDate and figure it out?
If you want to use DateComponent to store a repeating schedule, use nextDate(after:matching:matchingPolicy:) to find the next occurance of your schedule:
let dateComponents = DateComponents(calendar: .current, timeZone: .current, hour: 9, weekday: 2)
// 9AM of the next Monday
let nextOccurance = Calendar.current.nextDate(after: Date(), matching: dateComponents, matchingPolicy: .nextTime)!

DateTime JodaTime conversion

Please imagine the following:
I've this date in the Azores (GMT -1)
23/10/2010 23:00:00
And i want to convert this date to the following (the GMT +1)
24/10/2010 01:00:00
I want this behavior for any date in any timezone and the Date function with timezone give me the GMT -1 for this case.
Please note that i'm using JodaTime.
Thanks.
DateTime dateTime = new DateTime(2010, 10, 23, 23, 0, 0, 0, DateTimeZone.forOffsetHours(-1)); // (GMT -1) 23/10/2010 23:00:00
DateTime inAnotheTimeZone = dateTime.withZone(DateTimeZone.forOffsetHours(1));