get the next day and previous day of a selecteddate on flex! - apache-flex

I was wondering if there is a function/method to get next and previous date of a selected day
something like getpreviousday hh or something?
all I could find is function that people created themselves, I thought maybe there is already a built-in function.

Use this ActionScript DateUtils library.
There is a DateAdd method you can use:
var currentDate : Date = new Date();
var nextDate : Date = DateUtils.dateAdd('date',1,currentDate);
var previousDate : Date = DateUtils.dateAdd('date',-1,currentDate);

You can use the DateUtil from here: DateUtils at code.google.com
Further www.flextras.com mentioned the link for ActionScript Dateutils.

Related

Moment without time output date type not string

var moment = require('moment');
var c = moment().toDate();
How to output date without time in this format DD-MM-YYYY
Thanks
If you want to output the date in the format DD-MM-YYYY, simply use
var moment = require('moment);
var c = moment().format("DD-MM-YYYY");
toDate() converts the moment instance into a JS date, which it doesn't sound like you want to do.
I would advise looking at the Moment documentation for questions like this, it's very detailed and easy to understand.

Sage CRM - How to save a date with using the object returned from CRM.FindRecord()

Given this code:
var ToDateDate = new String(Request.Form("Comm_ToDateTime"));
ToDateDate = ToDateDate.split("/");
var newToDateTime = ToDateDate[2]+"-"+ToDateDate[1]+"-"+ToDateDate[0]+" "+Request.Form("Comm_ToDateTime_TIME")+":00.000";
CurrentCommunication("Comm_ToDateTime") = newToDateTime;
CurrentCommunication.SaveChanges();
How can i save the date?
This way the date (as Days, month and year) got saved but the hours, minutos does not.
The final output for the newToDateTime variable is 2016-19-09 08:50:00.000
if i use this value (2016-19-09 08:50:00.000) in a barehand SQL update, it works
Turns out that i have to build the Date object with the values and then use getVarDate() mehtod to to pass from a Date Javascriopt object to a record’s date field value which at the end it is the same i was doing :S
Found my answer in this Sage CRM Community

Get the minutes that have elapsed through moment diff

I'm trying to get the difference in minutes between two timestamps
I have a timestamp that looks like this to begin with
'15:44:06'
And when I want to find the time elapsed I create a new moment timestamp
var currentTimestamp = Moment(new Date()).format('HH:mm:ss');
Which returns this
'15:42:09'
I then attempt to get the difference like so
var duration = Moment.duration(Moment(currentTimestamp,'HH:mm:ss').diff(Moment(userTimestamp,'HH:mm:ss')));
And then attempt to get it in minutes
var elapsedTime = duration().asMinutes();
console.log(elapsedTime);
But in the console when I log it I get this error
var elapsedTime = duration().asMinutes();
^
TypeError: object is not a function
I got most of this code from this stackoverflow
You can get the diff by using the moment constructor properly.
First, when you initialize your time stamp, you should use the following format:
var timestamp = moment('15:44:06','HH:mm:ss');
Second, when you want to use the diff function with the current time you should user it like so:
timestamp.diff(moment());
Then, the given number can be converted to minutes with .asMinutes() (the first )
for further information you should read the official docs here.
You can also try this with the lastest moment.js
var start = moment('15:44:06','HH:mm:ss');
var minutesPassed = moment().diff(start, 'minutes');
This question is getting a little bit old, this answer just bring the state up to date with a solution the question was looking for:
const startDate = moment();
...
elapsedDuration = moment.duration(moment().diff(startDate));
//in minutes
elapseDuration.asMinutes();
As per documentation about diff
and display duration in minutes

Regex verification correct birth date and check age

I need a regex which takes the string YYYY-MM-DD-XXXX (The last 4 are just for purpose of gender/area) It's mostly important to check the first 8 Digits for a valid birth date.
So far i have this:
/^([0-9]{4})\-([0-9]{2})\-([0-9]{2})\-([0-9]{4})$/
Also i want to check so the input age is at least 18 years old. Would appreciate if somone had some input on how to achieve this.
Edit: The regex above was tested in JS, but should work fine in ASP as well?
I have changed your regex a bit to make it look more authentic
^([1-2]\d{3})\-([0-1][1-9])\-([0-3][0-9])\-([0-9]{4})$
years like 3012 will not pass.
Now you want to find whether a person is 18 years or not.
One approach could be to find the difference between the years of dates provided like this
var str = '1990-09-12-5555';
var res = /^([1-2]\d{3})\-([0-1][1-9])\-([0-3][0-9])\-([0-9]{4})$/.exec(str);
var year_now = new Date().getFullYear();
console.log(year_now-res[1]);
a second approach will be more precise one :
var str = '1990-09-12-5555';
var res = /^([1-2]\d{3})\-([0-1][1-9])\-([0-3][0-9])\-([0-9]{4})$/.exec(str);
var todays_date = new Date();
var birth_date = new Date(res[1],res[2],res[3]);
console.log(todays_date-birth_date);
will output the result in milliseconds. You can do the math to convert it into year
Cheers , Hope that helps !
I suggest using moment.js which provides an easy to use method for doing this.
interactive demo
function validate(date){
var eighteenYearsAgo = moment().subtract("years", 18);
var birthday = moment(date);
if (!birthday.isValid()) {
return "invalid date";
}
else if (eighteenYearsAgo.isAfter(birthday)) {
return "okay, you're good";
}
else {
return "sorry, no";
}
}
To include moment in your page, you can use CDNJS:
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.4.0/moment.min.js"></script>
Source
The following will match any year with a valid day/month combination, but won't do validation such as checking you've not entered 31 days for February.
^[0-9]{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])\-[0-9]{4}$
Not sure exactly what you're trying to achieve but I'd suggest using a date library for this sort of thing. You could return a message to the user somehow if the entered date fails to parse into an object.
In order to do age validation, you will certainly need to use a library so a regex should only be used for date validation purposes

SelectedDate not setting properly on the load in Flex

SCinitiationtarget.selectedDate = new
Date(rows1[i]['InitiationTarget']);
I am setting my seletedDate in my DateChooser like this. The format i am getting from the Database is 2009-12-30.
Its displaying in correctly.
I believe the date object doesn't recognize the dash as a valid separator. You'll have to some how reformat your date objects.
For example this works:
var date:Date = new Date("2009/12/30");
myDateChooser.selectedDate = date;
But this doesn't:
var date:Date = new Date("2009-12-30");
myDateChooser.selectedDate = date;
For more information on what date formats are valid, see the documentation here: http://livedocs.adobe.com/flex/3/langref/Date.html#Date%28%29
The first argument of Date constructor is called yearOrTimeValue and as its documentation says it accepts either year or time in UTC milliseconds. For proper Date construction use:
new Date(2009, 12, 30)
I got the solution finally.
var dateStr:String = dateFormatter.format(rows1[i]['InitiationTarget']);
SCinitiationtarget.selectedDate = new Date(dateStr);
<mx:DateFormatter id="dateFormatter" formatString="MMM D, YYYY"/>
With this the problem gets solved.
Why not use the parse method of the Date class?
SCinitiationtarget.selectedDate = Date.parse(rows1[i]['InitiationTarget']);

Resources