Valdiation From To date - winforms

I am developing Windows Form using vs2010 C#
I have 2 datetime pickers
1 is fromDatePicker and the other is ToDatePicker
I want to validate that the toDate is always after from date are the same day
eg if From:30/8/2010...To:16/8/2010
An error message is showed to user.

You can do comparisons on `DateTimes'
if (toDate < fromDate)
{
MessageBox.Show("To date is before from date");
}
If you're not worried about the time portion then use the Date property:
if (toDate.Date < fromDate.Date)
{
MessageBox.Show("To date is before from date");
}

Can you set a minimumDate property on your toDate control to the date on the fromDate control?

Related

React - How to display converted datetime?

In react app, I am getting an timestamp like 1635424532797 and I am converting and trying to display a date using new Date(1635424532797).toLocaleDateString("en-US").
Right now I am getting Invalid Date for this.
I am getting createdAt timestamp from backend data and parsing it to Date function.
How can I display a date (or datetime) here? Please help me to solve this issue.
This is an example how to do Date in javascript, sample does new Date object with string and formats to en-GB
const date = new Date(YOURDATE)
date.setDate(date.getDate());
const formattedDate = date.toLocaleDateString('en-GB', {
day: 'numeric', month: 'short', year: 'numeric'
}).replace(/ /g, ' ');

Lightning Flow Query

I am creating the lightning flow. In which, I need to provide the date in the 'field1' (Type : Date) in the screen component.
In the screen component, the 'field1' should only accept the date value which is in the range of 3years in the past of the current date and 2 years in the future of the current date.
For instance, if a user is entering the value in the 'field1' Date field on 5/13/2021 then the valid date range is between 5/13/2018 thru 5/13/2023.
Can anyone please guide/assist on how to achieve this.
Thanks in advance.
enter image description here
To create this date field you need to use following formula
IF(OR(
({!Accepted_Date} <= (DATE(YEAR({!$Flow.CurrentDate}) - 3,MONTH({!$Flow.CurrentDate}),DAY({!$Flow.CurrentDate}) - 1))), ({!Accepted_Date} >= (DATE(YEAR({!$Flow.CurrentDate}) + 2,MONTH({!$Flow.CurrentDate}),DAY({!$Flow.CurrentDate}) + 1)))
), false, true
)

How to get formatted DateTime irrespective of the time zone in salesforce

We use formatGMT() or format() methods of date time object in apex, it returns the formatted date based on the time zone. Although what should be done if we have a static date, such as date of birth that needs to be formatted, irrespective of the local time zone.
In my scenario when using DateTime.format(), The date of birth is showing correctly for users in India, although for the users in US, yesterday's date is displayed in some cases. In some cases it's converted correctly.
For eg. The dob for x person is 1995-09-20 which gets formatted to 09/20/1995,
Whereas for y person, the same method generates a formatted date 05/15/1990 when dob is 1990-05-16.
Basically the formatted date should be the exact replica of the dob, irrespective of time zone.
Method:
private static String localeFormatDate (Date dateValue) {
try{
String format = String.isNotBlank (strDateFormat) ? strDateFormat: 'MM/dd/YYYY';
Date myDate = Date.newInstance (dateValue.year(), dateValue.month(), dateValue.day());
Time myTime = Time.newInstance(0, 0, 0, 0);
return DateTime.newInstanceGMT (myDate, myTime). format GMT (format);
} catch (Exception ex){
return null;
}
}
Additionally, I have also tried to set timezone as Asia/Colombo as the date is correctly formatted in that time zone:
return DateTime.newInstanceGMT(myDate, myTime).format (format, 'Asia/Colombo');
Although I'm not sure if that would generate the correct format date based on the when the method runs.

Get month from datefield

I using Django-rest and I want to get month form Datefield in AngularJS.
My code is date = '2014-2-30' and I get month: var x = (new Date (Date.parse (date).getMonth().
But x = 1 and value of year = 114.
I read https://docs.angularjs.org/api/ng/filter/date but I can't do it. Would you give me example?
Django REST Framework should pass dates back to Angular in ISO 8601 format (yyyy-MM-dd), so there shouldn't be an issue parsing it on Angular's side.
{{ obj.date | date:"MMMM" }}
MMMM is the Angular date code for the full month (January-December). You can find other Angular date codes in the date filter documentation.

Assign date in salesforce.

I have written a batch job. In this batch job i have a condition to take date > = 1/1/2012
I am not able to give the date in the query. can you please help me.
global Database.QueryLocator start(Database.BatchableContext BC) {
system.debug('Inside start');
//date mydate = date.valueof(1/1/2012);
return Database.getQueryLocator('select name from opportunity');
}
I have given it in 2 ways
1st is :
took the date into a date field and give the condition as date >= :mydate
(shows an error in debug log as Invalid date: 0 )
and
2nd way when i gave the date their itself as date >=: 1/1/2012
(it shows as error in debug log as unexpected token: / )
can you please help me
Thanks
Anu
You must follow the proper date format
YYYY-MM-DD
select name from opportunity where mydate >= 2012-01-01
More information here

Resources