Format Datetime in Business Objects - datetime

So I know I can use =FormatDate(MyDate ,"mm/dd/yy") to turn a date into a string. I am then trying to add on a time:
=FormatDate(AdminDate ,"mm/dd/yy") + MyTime
Which works, however, I need to format this back to a datetime field (as I need to compare against a preexisting datetime field). I try using Todate(), but the documentation is very light, and provides very little on what is acceptable in the formatting of the date area, and nothing in the way of time!
I have attempted:
=ToDate(FormatDate(MyDate ,"mm/dd/yy HH:mm:ss") + MyTime ,"mm/dd/yy HH:mm:ss")
but this will only work when there is no time (and it just nulls out the time) and any row with a time will return a #ERROR
Anyone have an insight on formatting datetimes?
Thanks

The correct way to use the FormatDate command to output date and time components together in 12 hour format is:
=FormatDate(AdminDate; "MM/dd/yy hh:mm:ss a")
and in 24 hour format is:
=FormatDate(AdminDate; "MM/dd/yy HH:mm:ss")
Note MM is used in months and mm in minutes.

Related

How to convert the UTC date into local date in Moment.js?

I have a date in this format "2020-12-16T02:48:00" that came from the server. How can I convert this into local date and time? I tried some code but couldn't succeed.
Below is the attempt that I had made in angular after receiving date from the server.
response.data.map(date=>{
var centralDate = moment( date).zone("-06:00");
date = moment(centralDate).local().format('YYYY-MM-DD hh:mm:ss');
})
If indeed the value is in UTC (as per the title of your question), and it looks like "2020-12-16T02:48:00", and you want to convert it to local time, then you should do the following:
moment.utc(date).local().format('YYYY-MM-DD HH:mm:ss');
That does the following:
Parses the input in terms of UTC
Converts it to local time
Formats it as a string in the given format
Note also that you had hh in your original format. That is for hours in a 12-hour time format and thus you shouldn't use it without also using either A or a to indicate AM/PM or am/pm. Otherwise HH is for hours in a 24-hour time format.
If your issue is that the timezone doesn't change you can resolve using utcOffset (https://momentjscom.readthedocs.io/en/latest/moment/03-manipulating/09-utc-offset/) in this way:
response.data.map(date=>{
date = moment( date).utcOffset(-360);
})
Where 360 is the conversion fo the hours in minutes
var d= new Date();
d = new Date(d+ "Z")
I am not an expert in angular but I guess the trouble in your date is the word “T”. May be using string removal function you can remove the word “T” and then it becomes a proper date time value?

Converting Datetimes returns Null

I'm trying to convert a datetime that looks like this: 2017-09-19T07:00:00-07:00 into EST, but i keep getting Null values when using the hive built in UTC conversion.
I've tried using a regular expression to parse the date:
date_format(from_unixtime(unix_timestamp(2017-09-19T07:00:00-07:00, "yyyy-MM-dd'T'HH:mm:ss")
- (cast(regexp_extract(regexp_extract(2017-09-19T07:00:00-07:00, '(-[0-9][0-9]:[0-9][0-9])$', 1),'(-[0-9][0-9])',1) as int)*3600) -18000),'YYYY-MM-dd HH:mm')
but that's not good, since there's an hourly difference based on the time of year.
I've also tried:
FROM_UTC_TIMESTAMP(UNIX_TIMESTAMP(2017-09-19T07:00:00-07:00, "yyyy-MM-dd'T'hh:mm:ss:SSS'ZZZZZ'") * 1000, 'EST')
and
FROM_UTC_TIMESTAMP(UNIX_TIMESTAMP(2017-09-19T07:00:00-07:00, "yyyy-MM-dd'T'hh:mm:ss:SSS'Z'") * 1000, 'EST')
but that appears to not work either. What am I doing wrong?
I think that this method needs the date as a string like this:
date_format(from_unixtime(unix_timestamp('2017-09-19T07:00:00-07:00', "yyyy-MM-dd'T'HH:mm:ss")
Normally, the date formats are for strings, not for integers or numbers.
I found the answer on my own by combining the two ways of running the query.
date_format(
FROM_UTC_TIMESTAMP(
(unix_timestamp('2017-09-19T07:00:00-07:00', "yyyy-MM-dd'T'HH:mm:ss")
+ (cast(
regexp_extract(
regexp_extract('2017-09-19T07:00:00-07:00', '(-[0-9][0-9]:[0-9][0-9])$',1),'(-[0-9][0-9])',1) as int)
*-3600)
)*1000 ,'America/New York')
,'YYYY-MM-dd HH:mm:ss')
You are getting NULL because the pattern (format of the date and time) you have provided is not matching with the actual date time value. Correcting the date time format in your query would resolve this issue:
select from_unixtime(UNIX_TIMESTAMP("2017-09-19T07:00:00-07:00", "yyyy-MM-dd'T'HH:mm:ssXXX"), "yyyy-MM-dd HH:mm:ss");
Check out this link to know more about the date time patterns: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html

ASP.NET "String was not recognized as a valid DateTime."

First off, I realize there's a million pages discussing this already. I have looked at least a hundred of them but cannot seem to make this work. My date and time is presented as a string, compiled from javascript to grab client's local time. It is formatted like this: 7/11/2015 8:34 PM.
I currently have:
Dim datetimeformated = DateTime.ParseExact(lblDateTime.Text, "MM/dd/yyyy HH:mm tt", CultureInfo.InvariantCulture)
I have tried many different variants, but this should be correct I think, yet it does not work. Any help is greatly appreciated. TIA
The correct format for your case is: M/dd/yyyy h:mm tt, and perhaps even, M/d/yyyy h:mm tt, if you can have the day of the month as a single digit.
Explanation: Why your format string didn't work.
MM: means that you must always have 2 digits for the month, clearly not the case in your example.
dd: again, means that you must always have 2 digits for the day of the month. Is that the case? Adjust the parameter if needed.
HH: This actually means that you are expecting the hour value as 2-digits using the 24-hour clock (00-23), which is clearly wrong on both accounts. You can have a single digit, and you are not using the 24-hour clock, because you are using the AM/PM designator.
Relevant documentation link: Custom Date and Time Format Strings.

C# format of date issue

My problem: I need to get date format as "mm/dd/yyyy"
Scenario:
I have declared DateBirth as nullable DateTime.
The value I get when I use:
AdvancedObj.DateBirth .Value.ToString()
is: "13/03/2013 00:00:00"
The value I get when I use
AdvancedObj.DateBirth .Value.ToString(CultureInfo.InvariantCulture)
is :"03/13/2013 00:00:00"//This is roughly correct but, I do not need 00:00:00
I have tried this as well, but the format is correct and value is incorrect.
AdvancedObj.DateBirth.Value.ToString("dd/mm/yyyy",CultureInfo.GetCultureInfo("en-Us"))
**"13/00/2013"**
Can anybody point me, what am I missing?
Use the right format string for months - it is MM. mm is for minutes:
AdvancedObj.DateBirth.Value.ToString("MM/dd/yyyy",CultureInfo.InvariantCulture)
Also, order them correctly as above - if you want months before days, use MM/dd/yyyy, if the other way around, dd/MM/yyyy.
I suggest you take a good long read of Custom Date and Time Format Strings on MSDN.
Month are 'M'. 'm' is for minutes.
"dd/MM/yyyy"

DateTime format conversion to string ignores AM/PM

I am trying to convert DateTime object to string using formatting but due to some strange reason, it ignores AM/PM. It would just take the magnitude of the Hour in the object.
I am using the following format:
StartDate.ToString("yyyy-MM-dd hh:mm:ss.fff");
and
String.Format("0:yyyy-MM-dd hh:mm:ss.fff", StartDate);
I don't think that there is a difference between the two, but just wanted to give it a try. If I pass a value 4/28/2012 6:00:00 AM or 4/28/2012 6:00:00 PM, the result is the same "2012-04-27 06:00:00.000"
You've used hh which uses the 12-hour clock. You want HH which uses the 24-hour clock.
See MSDN for more details about custom format strings.
Note that you may wish to specify the invariant culture, unless you really want the time separator to depend on the current culture:
string formatted = StartDate.ToString("yyyy-MM-dd HH:mm:ss.fff",
CultureInfo.InvariantCulture);
(Note that you shouldn't have the braces if you're passing the format string to ToString. I'll assume this was just a typo in the question.)
If you want to use the 12-hour clock, use tt in the format string to produce the AM/PM designator.

Resources