</my-date-picker> using ngmodel how should i convert date format and send - angular2-template

I am getting date like this 2018-10-17T00:00:00.000Z i should convert to 17.10.18 and send through [(ngModel)] by using my date picker
Can you help me.

got solution.
var availYear = moment(availDate).format("YYYY");
var availMonth = moment(availDate).format("M");
var availDay = moment(availDate).format("DD");
this.model = { date: { year: availYear, month: availMonth, day: availDay } };

Related

What is the preferred way of working with dates and JavaScript?

When working with a Faunadb record that contains a date value, I struggled with using that date in JavaScript. Eventually I got it working like so:
project.shipDate = new Date(await client.query(q.Format('%t', project.shipDate)));
This seems fine, but I also noticed I could do this:
let test = JSON.parse(JSON.stringify(project.created));
console.log(test);
datetest = new Date(test["#date"]);
Which seems wonky (grin), but may be quicker as it's not using the Fauna client library. Which should I prefer?
The JS driver has several helper classes that let you cast the javascript Time and Date objects to their FQL counterparts.
Here is an example.
From Fauna to JS
You can create a new document that contains a date value.
const project = await client.query(
q.Create(
q.Collection("projects"),
{ data: { shipDate: q.ToDate(q.Now()) } }
)
)
You can retrieve the date value and use as a javascript Date object by using the value property
const shipDate = new Date(project.data.shipDate.value)
From JS to Fauna
The date value can be modified however you want, and you can pass it back to FQL using the values.FaunaDate class.
const { values } = require('faunadb')
/* ... */
let nextDay = new Date(shipDate.getTime() + 86400000)
const faunaDate = new values.FaunaDate(nextDay)
Full Example
const project = await client.query(
q.Create(
q.Collection("projects"),
{ data: { shipDate: q.ToDate(q.Now()) } }
)
)
console.log(project)
const shipDate = new Date(project.data.shipDate.value)
console.log(shipDate)
let nextDay = new Date(shipDate.getTime() + 86400000)
console.log(nextDay)
const projectRef = project.ref
const projectUpdate = await client.query(
q.Update(
projectRef,
{ data: { shipDate: new values.FaunaDate(nextDay) } }
)
)
console.log(projectUpdate)
{
ref: Ref(Collection("projects"), "307924674409398337"),
ts: 1629918703380000,
data: { shipDate: Date("2021-08-25") }
}
2021-08-25T00:00:00.000Z
2021-08-26T00:00:00.000Z
{
ref: Ref(Collection("projects"), "307924674409398337"),
ts: 1629918703470000,
data: { shipDate: Date("2021-08-26") }
}

How to change xAxisTickFormatting in ngx-charts-line-chart based on timeline selection?

By default, ticks are formatted based on time range selection in timeline. If it pans across days it shows month and if it is with in a day, it shows only time. This is great!
Now I want to localize these ticks. I could provide xAxisTickFormatting to get this done but I want to have the formatting based on the time range selection. "MMM DD" or "HH:MM" based on the current time range selection.
For this I need to change the formatting function dynamically on time range selection event. Is there such an event? Or is there any other way to achieve this?
In your chart, among the other attributes, you can declare
<ngx-charts-bar-horizontal-normalized
...
[xAxis]="true"
[xAxisTickFormatting]='formatPercent'
...
</ngx-charts-bar-horizontal-normalized>
formatPercent is a function declared in your .ts file (I'm using Angular) written like
formatPercent(val) {
if (val <= 100) {
return val + '%';
}
}
For any reference check the documentation here
Hope this helps.
It looks like, date is formatted based on the d3 logic. It uses the precision available to that tick. So if date is 12/15/2020 11:30:00, precision is at minute level. Similarly if date is 12/15/2020 00:00:00, precision is at day level.
Now we can choose the format options accordingly.
var locale = 'fr-FR'; // 'en-US'
function formatDate(value) {
let formatOptions;
if (value.getSeconds() !== 0) {
formatOptions = { second: '2-digit' };
} else if (value.getMinutes() !== 0) {
formatOptions = { hour: '2-digit', minute: '2-digit' };
} else if (value.getHours() !== 0) {
formatOptions = { hour: '2-digit' };
} else if (value.getDate() !== 1) {
formatOptions = value.getDay() === 0 ? { month: 'short', day: '2-digit' } : { weekday: 'short', day: '2-digit' };
} else if (value.getMonth() !== 0) {
formatOptions = { month: 'long' };
} else {
formatOptions = { year: 'numeric' };
}
return new Intl.DateTimeFormat(locale, formatOptions).format(value);
}
var dates = ['12/15/2020 11:30:30', '12/15/2020 11:30:00', '12/15/2020 11:00:00', '12/15/2020 00:00:00', '12/13/2020 00:00:00', '12/01/2020 00:00:00', '01/01/2020 00:00:00'];
for (date of dates) {
console.log(date, '=>', formatDate(new Date(date)));
}
Now this function can be used as
<ngx-charts-line-chart
[xAxis]="true"
[xAxisTickFormatting]="formatDate">
</ngx-charts-line-chart>

how to display date in set timezone using angular2

how to display date in set time
{{ mydate | date : DATE_FORMAT.DD_MMM_YYYY : 'America/New_York'}}
not working.
Pls try this, it worked for me
in your component,
import { DatePipe } from '#angular/common';
private myDate:any = new Date();
constructor() {
if(this.myDate != ""){
this.myDate = new DatePipe("en-US").transform(this.myDate, 'dd-MM-yyyy');
}else{
this.myDate = "";
}
}
In your html,
<div> {{myDate}} </div> /* you get your date in dd-mm-yyyy format*/
Hope this helps

TypeError: expected dynamic type 'double' but had type 'string'

I'm running into this error when trying to use datePickerAndroid and setting the state afterwards.
Error Message
I feel like the problem may be from the initial state being a new Date() but not 100% sure.
_isAndroid = async () => {
let {action, year, month, day} = await DatePickerAndroid.open({
date: this.props.startDate,
});
if (action === DatePickerAndroid.dismissedAction) {
this.props.closeModal()
} else {
const date = year + "-" + month + "-" + day
this.props.onDateChange(date)
}
}
Prop Function:
onDateChange = (newDate) => {
this.setState({currentDate: newDate}) // <- This one is breaking
let dates = this.state.dates;
let index = this.state.currentIndex;
if (this.state.currentKey === "start") {
dates[index].start = newDate
} else {
dates[index].end = newDate
}
this.setState({dates: dates});
}
I've narrowed it down to the first setState, and I've tried making the initial state a string as well as setting the state to a simple string but still getting the error.
For DatePickerAndroid
expected dynamic type double
In other words native component wants time, but you put string. You this.props.startDate is string, transfer time in time format. Example:
const {action, year, month, day} = await DatePickerAndroid.open({
date: new Date() // <- This is Date, not string!
});
Good luck!

add date to ad text adwords

I want to create ad that change the date every day.
this is the script that I am running every day at 00:00:
var date_format = Utilities.formatDate(new Date(), "GMT", "dd/MM/y")
var AD_GROUP_NAME = 'ארונות הזזה';
function main() {
var adGroup = getAdGroup(AD_GROUP_NAME);
var keywords = adGroup.keywords().get();
while (keywords.hasNext()) {
var keyword = keywords.next();
keyword.setAdParam(1, date_format);
}
}
function getAdGroup(name) {
var adGroupIterator = AdWordsApp.adGroups()
.withCondition('Name = "' + name + '"')
.withLimit(1)
.get();
if (adGroupIterator.hasNext()) {
return adGroupIterator.next();
}
}
and in the ad I added a text that is including {param1}.
This is not working, do you know why?
Thank you,
Omry.
This is not the way to do it.
You should check ad customizer instead of ad params.
Have a look.
https://developers.google.com/adwords/scripts/docs/features/ad-customizers
Here you have a really nice examples. :)