How to change date time format in angular-bootstrap-datetimepicker - datetime

I am new to angular, not able to change date time format in my calendar module. I am using angular-bootstrap-datetimepicker. Basic config as below
<dl-date-time-picker
maxView="day"
minView="day"
startView="day"
minuteStep="5"
[(ngModel)]="selectedDate">
</dl-date-time-picker>
Want to change from (EEEE, MMMM d, y, h:mm:ss a zzzz) format to (yyyy/mm/dd) format

I think you are trying to change for format of the date displayed in an input box - use https://dalelotts.github.io/angular-bootstrap-datetimepicker/directives/DlDateTimeInputDirective.html

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?

Power Query - Change DateTime to Text without altering format

I'm trying to convert a DateTime field to Text in Power Query.
Currently the DateTime format is dd/mm//yyyy hh:mm:ss (e.g. 02/04/2006 00:00:00)
When I change the type in Power Query to Text, the output is formatted as mmmm d yyy hh:mm AM/PM (e.g. Apr 2 2006 12:00AM)
I want to retain the original format when I convert to text, how can I do this?
Thanks
There isn't really an "original format" when it's stored as DateTime, it's just how your program chooses to represent it (which can vary regionally).
That said, you should be able to specify exactly the format you want. When you use the GUI to transform the data type it will produce a step that looks like this:
= Table.TransformColumnTypes(#"Previous Step",{{"Column1", type text}})
Modify that a bit so it looks like this instead:
= Table.TransformColumns(#"Previous Step",
{{"Column1", each DateTime.ToText(_, "MMM d yyyy hh:mm tt"), type text}})

How to force DateTime field in Quicksight on string column?

I have a data set that has dates like so:
datetimecreated
2019-09-14 06:06:15.863383
2019-09-14 06:06:16.863385
When I go to edit my data set and force column datetimecreated into datatype date time, I get error:
Known date formats were not detected in this data. Provide a date format to transform this data into a known date format.
The data format I am trying to pass is this:
yyyy-MM-dd HH:mm:ss.ffffff
What am I doing wrong that this can not be detected as date field by Quicksight?
I've even tried this format:
yyyy-MM-dd HH:mm:ss
get same error as above.
First check would be if the date format is accepted in quicksight:
Quicksight User Guide pg.71
I don't think "yyyy-MM-dd HH:mm:ss:SSSSSS" is an accepted format.
In which case you may want to just extract the datetime data from the string to the most relevant format so that is usable for your analysis.
To do so you can create a calculated field based on your "datetimecreated" field using the parseDate() function:
parseDate(date, [format], [time_zone])
It's possible to create a calculated field either in the "Edit Data" section of the dataset by selecting it the dropdown menu for the "datetimecreated" field in the field list OR by selecting the option in the "Add" menu within a specific analysis.
Inserting your data into the formula would look something like this:
parseDate({datetimecreated}, yyyy-MM-dd HH:mm:ss, [time_zone])
This should create a date field with the extracted date information that you can then manipulate as with any other date and aggregate by DAY, MONTH etc.
I had this issue, I used this page for that correct formats:
https://docs.aws.amazon.com/quicksight/latest/user/parseDate-function.html
The format I required was yyyy-MM-dd'T'HH:mm:ssZ
Correct format is yyyy-MM-dd HH:mm:ss:SSSSSS

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"

How to convert date to mm/dd/yyyy format

I want to convert dateformat to mm/dd/yyyy. Whatever dateformat is coming in textbox, I want to convert it into mm/dd/yyyy.
First you need to get it into a datetime object. The most common standards work via:
DateTime x = DateTime.Parse(txtDate.Text);
If you expect a freaky format, you still have to know what format it is:
DateTime x;
DateTime.TryParseExact(txtDate.Text, "YYddd", out x);
Then simply output the data:
string date = x.ToString("MM/dd/yyyy");
But you really need to enforce your formatting using regex, validators, scout's honor - something.
see MSDN for full details.
You will need to parse the input to a DateTime object and then convert it to any text format you want.
If you are unsure what format you may be getting, maybe it is a good idea to restrict the user to a single format (using validation or better yet a date picker).

Resources