I want to get tomorrows date using exslt date.
date:date() returns todays date ('2014-01-23') and if I am adding 1 day ('P1D'), I expect it to be tomorrow ('2014-01-24'). But instead the result of
<xsl:value-of select="date:add(date:date(), 'P1D')"/>
is '2014-01-23T23:00:00Z'.
It took me some time of research but finally I solved the problem:
The problem with my previous implementation was caused by the timezone. The exact return value of date:date() is '2014-01-23+01:00' (a date with timezone; for me it's +01:00).
Adding a duration via date:add(string, string) seems to have a problem with that. So to get the correct result I just cut off the timezone from todays date. The result of
<xsl:value-of select="date:add(substring(date:date(), 1, 10), 'P1D')"/>
is tomorrows date ('2014-01-24') as expected.
Related
With today's date, I should get the 16th date of next month.
For example, on passing 13-12-2021, I should get 16-01-2022.
I need to get the next month 16th day from current date (input date). Examples:
On passing 13-11-2021 should get 16-12-2021.
On passing 14-11-2021 should get 16-12-2021.
On passing 15-11-2021 should get 16-12-2021.
On passing 02-12-2021 should get 16-01-2022.
On passing 03-12-2021 should get 16-01-2022.
On passing 03-01-2022 should get 16-02-2022.
On passing 04-01-2022 should get 16-02-2022.
Any help will be much appreciated. Thanks.
java.time
One of the many strong points of java.time, the modern Java date and time API, is date arithmetic like this.
public static LocalDate nthDayOfFollowingMonth(
int desiredDayOfMonth, LocalDate currentDate) {
return YearMonth.from(currentDate)
.plusMonths(1)
.atDay(desiredDayOfMonth);
}
Try it out with your example date:
System.out.println(nthDayOfFollowingMonth(
16, LocalDate.of(2021, Month.DECEMBER, 13)));
Output:
2022-01-16
We might not have needed to convert to YearMonth and back to LocalDate. Doing so relieves both me and the reader of considering what happens if today’s day of month doesn’t exist in next month — for example if current date is 30 January (there is no 30 February). What one still wants to consider is what happens if you request a day of month tht doesn’t exist next month. For example on 13 January asking for the 30th of next month. We can try that out too:
System.out.println(nthDayOfFollowingMonth(
30, LocalDate.of(2022, Month.JANUARY, 13)));
I find the result very reasonable:
java.time.DateTimeException: Invalid date 'FEBRUARY 30'
I'm in a GMT+1 timezone.
Function startOfDay should return "the first moment of the given date".
In my case for date "2020-11-10 19:52:52 +0000\n" I should get "2020-11-10 00:00:00 +0000\n", but I'm getting "2020-11-09 23:00:00 +0000\n" (desired time - 1 hour).
As you can see in the screenshot, variable is set up correctly, but when I try to print it, it is magically converted. It looks like swift is converting it on the fly, but why?
At first, I thought that maybe somehow I have different timezone for Calendar object, but when I print Calendar.current.timeZone.abbreviation() the result is "GMT+1", same as for Date object or TimeZone.current.abbreviation().
Xcode playground
--eval "var date = new Date(); date.setDate(date.getDate()-10)"'
pause
new Date() gives me the current date. I'm trying to get 10 days back date,but setDate() not setting the date correctly.I'm doing it through batch script.
I got this 1576031482772 after evaluating date.setDate(date.getDate()-10) .Please help me find a solution.
This is the expected behavior. The signature of setDate is as follows. ref
Parameters
It accepts one parameter, it should be number as a day value.
Return Value
It returns milliseconds between 1 January 1970 00:00:00 UTC and the given date
Solution
You are actually setting the day value of date. So If you want to retrieve the value, just use date.getDate(). Which will be the new date.
For more details, how it works, you can refer MDN.
For all of my dates, Format subtracts exactly 4 hours from the hour field.
Here is an example for clarification:
When I retrieve a date in Microsoft SQL Server Management Studio, the date column returns dates in this format: 2014-10-30 11:19:02.733.
When I execute the same command using sql and display the value in a gridpanel, it is displayed in this format: 2014-10-30T11:19:02.733.
However, When I try to use Format="yyyy-M-d, HH:mm", the date is returned as 2014-10-30 07:19:02.
For easier comparison, this is what the difference is:
2014-10-30 11:19:02.733
2014-10-30T11:19:02.733
2014-10-30 07:19:02
What could cause the removal of exactly 4 hours every single time?
Thank you.
Additional code:
<ext:DateColumn ID="Column6" runat="server" Text="When" DataIndex="time" Flex="1" Format="yyyy-M-d, HH:mm" />
For anyone who stumbles upon this question in the future:
I found the solution, based on Julien's guess!
I changed the timezone on my pc and it consequentially changed the value again.
It turns out, that the way around this is is to add a type to the modelField. It would look something like this <ext:ModelField Name="time" Type="Date" />.
For some reason, this prevents the client-side time-zone override.
Pulling my hair out again...
I need to calculate the difference between two dates in days. I'm doing this:
<cfset d = DateDiff("d", Dateformat( active_apps.app_base_coupon_start, "dd.mm.yyyy"), Dateformat( variables.useDate, "dd.mm.yyyy") )>
With active_apps.app_base_coupon_start = 27.07.2012 and variables.useDate = today = 02.10.2012.
I dumped both values, they are OK. However the dateDiff returns -168 when I was looking for (4 days in July, 31 in August, 30 in September, 2 in October) 67 days.
Question:
Can someone prevent me from losing my remaining hair and tell me what I'm doing wrong here or if there is an easier way to get the difference in days?
EDIT:
Ok, it also works like this:
<cfif DateAdd("d", active_apps.app_grace_time, Dateformat( active_apps.app_base_coupon_start, "dd.mm.yyyy") ) GT now()>
<cfdump output="e:\s\page\t\dump.txt" label="catch" var="YUP">
<cfelse>
<cfdump output="e:\s\page\t\dump.txt" label="catch" var="NOPE">
</cfif>
but I would still like to know, why dateDiff is returning strange values.
DateDiff("datepart", date1, date2) takes a datepart and two date objects as arguments.
DateFormat() as Adam Cameron already said returns a string and not a date object.
ColdFusion is trying to read "27.07.2012" and "02.10.2012" as date objects by trying to apply some known date formats. That's why "02.10.2012" is interpreted as "Feb 10 2012".
I wouldn't let ColdFusion guess the dateformat of your string. Instead you should create date objects by using CreateDate(year, month, day).
now() is also a ColdFusion date object.
First things first, dateAdd() takes DATES as arguments, not dateFormat()-ed strings. dateFormat() is for output, not for calculations.
You need to understand that just because "02.10.2012" looks like a date to you (and to me), it's not a date as far as the computer is concerned: it's a string.
Never use strings for date calculations.
In your case, CF is valiantly trying to work out what "02.10.2012" might mean as a date, and deciding it's "mm.dd.yyyy" format, which is Feb 10, whereas you mean Oct 2.
You're using an ambiguous date format. Change the DateFormat to international date format (ISO 8601) whenever you make date calculations and things will be a bit more predictable. Note that CF doesn't support every variant of the ISO format, but for the most part you just need yyyy-mm-dd which is supported.
<cfset d = DateDiff("d", Dateformat( active_apps.app_base_coupon_start, "yyyy-mm-dd"), Dateformat( variables.useDate, "yyyy-mm-dd") )>