I developed a function in erlang which return date in this form for example: 15-Dec-2011
I want to convert this date in order to became in this case 15-12-2011 (so DEC became 12)
this is an example of date that should be converted
15-Dec-2011
19-Jan-2012
16-Feb-2012
15-Mar-2012
19-Apr-2012
17-May-2012
I will give basically the same answer with this post as the last post asking how to convert dates in erlang.
The easy solution is to use the ec_date or dh_date.
convert date in erlang
ec_date:format takes the format argument in a way similar to php's date function.
Related
Hi I want to filter my data which is between two Persian date.
Note: Persian date is a string data type like : "1400/02/23"
when I want to filter my table in SQL Server I simply write like the code bellow:
SELECT * FROM Table
WHERE Date >="1400/01/02" AND Date <="1400/05/10"
but in C# syntax I do not know how to fetch date between two string to use in my filter back-end code. If I simply compare the error raise that string type data can not use comparison operator.
I would be glad and grateful if somebody help me
First, convert Persian Date to Gregorian date and then do the comparison.
I am working on a code in Neo4j and want to find out the difference between two time columns. The date time is in format 20130508 19:14:56.913.
I also tried using APOC function, but I am getting the error that it is Unknown function. Could anyone please help me this.
I think you can use the APOC function apoc.date.parse. The function signature is:
apoc.date.parse(date, targetTimeUnit, format)
date should be a string representing the date you are converting to the specified targetTimeUnit (ms for target milliseconds, in the example). The date should be in the specified format, indicated by the third parameter.
Take a look in this example:
WITH apoc.date.parse('20130508 19:14:56.913','ms','yyyyMMdd HH:mm:ss.ms') AS initialTime,
apoc.date.parse('20130508 20:14:56.913','ms','yyyyMMdd HH:mm:ss.ms') AS finalTime
RETURN finalTime - initialTime as difference
The output will be:
╒════════════╕
│"difference"│
╞════════════╡
│3600000 │
└────────────┘
That is: a difference of 3600000 milliseconds between the two dates.
I want to compare string representations of weeks, e.g. week "01/17" is before "02/17" and after "52/16".
The following code throws an exception, I guess because my string doesn't hint at the exact day of each week. However, I don't care - it could all be Mondays or Thursdays or whatever:
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("ww/YY", Locale.GERMANY);
LocalDate date1 = formatter.parse(str1, LocalDate::from);
Do I need to modify the parser? Or parse to some other format? Unfortunatley there is no object like YearMonth for weeks...
One solution would be to always default to the same day, say the Monday. You could build a custom formatter for that:
DateTimeFormatter fmt = new DateTimeFormatterBuilder()
.appendPattern("ww/YY")
.parseDefaulting(ChronoField.DAY_OF_WEEK, 1)
.toFormatter(Locale.GERMANY);
You can now build LocalDates representing the Monday of the given week:
LocalDate d1 = LocalDate.parse("01/17", fmt);
LocalDate d2 = LocalDate.parse("52/16", fmt);
System.out.println(d1.isAfter(d2));
which prints true because 01/17 is after 52/16.
I wasn't able to find a way for this to work with the DateTimeFormatter class, but I would like to suggest a different approach.
The Threeten Extra library contains a number of classes that were deemed too specific to include in the java.time library. One of them is the YearWeek class you mention.
Your problem can be solved by parsing the week-number and year manually from the input-string and then invoking the YearWeek creator-method like this:
YearWeek yw = YearWeek.of(year, monthOfYear);
tl;dr
YearWeek.parse( "2017-W01" )
ISO 8601
Or parse to some other format?
Yes, use another format.
Use the standard ISO 8601 formats when serializing date-time values to text. The standard includes support for week dates.
For a year-week that would be four year digits, a hyphen, a W, and two digits for the week of the year.
2017-W01
Get clear on your definition of a “week”. The ISO 8601 definition is that:
The Week # 1 contains the first Thursday of the year, and
Runs Monday-Sunday.
So years run either 52 or 53 weeks long. And note that under this definition, the first few days of the year may be in the prior year when week-numbering. Likewise, the last few days of the year may be in the following year when week-numbering.
If you want to indicate a particular day within that week, append a hyphen and a single digit running 1-7 for Monday-Sunday.
Tip: To see ISO 8601 week numbers by default on your computer, you may need to adjust your OS setting. For example, on macOS set System Preferences > Language & Region > Calendar > ISO 8601 to make apps such as Calendar.app to display week numbers with this standard definition.
2017-W01-7
By the way, a couple of similar representations:
An ordinal date meaning the year and the day-of-year-number running from 1-366 is year, a hyphen, and a three-digit number: 2017-123
Month-Day without year is two hyphens, month number, hyphen, and day-of-month number: --01-07
Note that the use of Locale as seen in the Question is irrelevant here with the standard ISO 8601 formats.
YearWeek
Unfortunatley there is no object like YearMonth for weeks...
Ahhh, but there is such a class.
For a class to directly represent the idea of a week-year, see the correct Answer by Henrik. That Answer shows the ThreeTen-Extra library’s class YearWeek.
The YearWeek class can directly parse and generate strings in standard format.
YearWeek yw = YearWeek.parse( "2017-W01" );
You can compare the YearWeek objects with methods: compareTo, equals, isBefore, isAfter.
yw.isBefore( thatYw )
The ThreeTen-Extra project offers other classes such as YearQuarter that you may find useful.
This question already has an answer here:
Date parsing in Go
(1 answer)
Closed 6 years ago.
I have this date, in this format:
25.04.2016
I need to parse this into a Golang time object so that I can store it in my DB.
What is the best way to do so? I can't find a standard parsing format that will do so.
To parse a date in go you provide a format string that represents the date Mon Jan 2 15:04:05 MST 2006 so in this case it would look like;
t, _ := time.Parse("02.01.2006", "25.04.2016")
(play ground example; https://play.golang.org/p/6E9zshNeFG )
Check the packages docs here; https://golang.org/pkg/time/#example_Parse
I believe the arbitrary date you use as the example format is the first day of the Go programming language.
I am trying to use blew expression in Google SpreadSheet.
=min(GoogleFinance("HKDUSD","price",date(A2)-1,date(A2)))
But since A2 data is in mm/dd/year format, we need to convert it to yy,mm,dd format as parameter of date().Does Google SpeadSheet has some API to do such convert?
It actually works if you just add the dates as they are without the date function wrapped around them
=min(GoogleFinance("HKDUSD","price",L1-1,L1))
Edited: To answer your follow up question about the date format - a formulaic workaround you do uses regex replace and basically just swaps the two capture groups in month and day with this regex "(\w+)/(\w+)":
=min(GoogleFinance("HKDUSD","price",REGEXREPLACE(L1,"(\w+)/(\w+)","$2/$1")-1,REGEXREPLACE(L1,"(\w+)/(\w+)","$2/$1")))