In MySql I can use YEARWEEK() to receive the week and the related year of this week in one string. (E.g. SELECT YEARWEEK('1987-01-01'); which leads to "198653").
Is there anything like that in Oracle10g?
I only know about the TO_CHAR function. But if I use TO_CHAR(sysdate, 'YYYYIW'); I receive 198753 and not 198653. So, how I am able to calculate this correctly?
Does using IYYYIW format with TO_CHAR() make any difference? Note the "I" in the beginning instead of first "Y", it is for 4-digit year based on the ISO standard.
I can't reproduce your example that Oracle returns 198753.
select TO_CHAR(DATE '1987-01-01', 'YYYYIW') from dual returns 198701 for me which is correct according to the ISO definition of week numbers.
Oracle has another format mask WW (instead of IW) that uses the week where the first day of the year is in as week #1 - which again would return week number 1 for the January 1st.
Have a look here: http://en.wikipedia.org/wiki/Week_number#Week_numbering
I find MySQL's week number a bit strange actually, because no week numbering scheme I know would return week 53 for January 1st, 1987 (but that doesn't mean very much though...)
Related
What date time format is this : 735715:37344280
<ExecDateTOD Friendly="Monday April 27, 2015 10:23:00am">735715:37344280</ExecDateTOD>
It's found in C:\Windows\Performance\WinSAT\DataStore\file_name.xml, and is the date time when the Windows Experience Index Assessment test was run.
Any idea how it's structured and can be edited? I need to change it to a previous years Date.
It seems that this format is called VariantTime, in MSDN the call to convert time is called VariantTimeToSystemTime. So it may be number of days, with decimal part after the :.
For the timestamp 735715:37344280
The first number (the one before the colon) is the number of days since the year 0:
735715 / 365 = 2015.66
The second number (the one after the colon) is the number of milliseconds that have passed within the current day.
37344280 / (1000*60*60) = 10.37 hours since start of day
So you can just subtract 365 days from the first number to obtain the previous year like this:
<ExecDateTOD Friendly="Monday April 27, 2014 10:23:00am">735350:37344280</ExecDateTOD>
Note that there were no leap years in either 2015 or 2014, so these year are exactly 365 days long.
Here is a link to a page with another <ExecDateTOD> tag where you can compare: http://www.scribd.com/doc/82935159/2012-01-30-16-00-49-986-Formal-assessment-Recent-WinSAT#scribd
I think that if you subtract 365 from that number, you'll be in previous year.
That number seems to be days since the year 0. The first part might be the number of days, taking into account leap years, etc). The second part the time coded in some way.
I need to change the week start date from Monday to Saturday in PostgreSQL. I have tried SET DATEFIRST 6; but it doesn't work in PostgreSQL. Please suggest solution for this.
It appears that DATEFIRST is a thing in Microsoft Transact-SQL.
I don't believe Postgres has any exact equivalent, but you should be able to approximate it.
Postgres supports extracting various parts of a TIMESTAMP via the EXTRACT function. For your purposes, you would want to use either DOW or ISODOW.
DOW numbers Sunday (0) through Saturday (6), while ISODOW, which adheres to the ISO 8601 standard, numbers Monday (1) through Sunday (7).
From the Postgres doc:
This:
SELECT EXTRACT(DOW FROM TIMESTAMP '2001-02-18 20:38:40');
Returns 0, while this:
SELECT EXTRACT(ISODOW FROM TIMESTAMP '2001-02-18 20:38:40');
Returns 7.
So you would use a version of EXTRACT in your queries to get the day of the week number. If you're going to use it in many queries, I would recommend creating a function which would centralize the query in one spot, and return the number transposed as you would like such that it started on Saturday (the transposition would vary depending on which numbering method you used in EXTRACT). Then you could simply call that function in any SELECT and it would return the transposed number.
You can just add +x, where x is the offset between postgres dow and what you want to achieve.
For example:
You want Sunday to be the first day of the week. 2018-06-03 is a Sunday and you want to extract the dow of it:
SELECT EXTRACT(DOW FROM DATE '2018-06-03')+1;
returns 1
That is probably the reason why postgres dow yields 0 for Sunday. Would it be 7, then
SELECT EXTRACT(DOW FROM DATE '2018-06-03')+1;
would return 8.
Essentially I may have any date and I want to get the proper quarter-end date for the previous quarter.
Three examples:
19/07/2013 -> 30/06/2013
30/06/2013 -> 31/03/2013
28/02/2013 -> 31/12/2012
In Excel VBA it seems using DateAdd to subtract a quarter just subtracts three months from the date, e.g. 19/07/2013 -> 19/04/2013. This is no good for me.
What do you think would be the best way of doing this?
Perhaps extracting the month part and then comparing it to a list of the
possible quarters?
Or maybe having some sort of null date
01/01/2000 and then adding the number of quarters the given date
shows as to this null date and then subtracting a day to get a
previous quarter-end position (although this might cause problems
when the date flips under a year to December 31)?
Please consider:
=IF(MOD(MONTH(A1),3)=0,EOMONTH(A1,-3),
IF(MOD(MONTH(A1),3)=1,EOMONTH(A1,-1),
EOMONTH(A1,-2)))
Edit: There is a better answer in the comments.
I want to calculate the number of days passed between past date and a current date. My past date is in the format dd/mm/yyyy format. I have used below mentioned formulas but giving the proper output.
=DAYS360(A2,TODAY())
=MINUS(D2,TODAY())
In the above formula A2 = 4/12/2012 (dd/mm/yyyy) and I am not sure whether TODAY returns in dd/mm/yyyy format or not. I have tried using 123 button on the tool bar, but no luck.
The following seemed to work well for me:
=DATEDIF(B2, Today(), "D")
DAYS360 does not calculate what you want, i.e. the number of days passed between the two dates – see the end of this post for details.
MINUS() should work fine, just not how you tried but the other way round:
=MINUS(TODAY(),D2)
You may also use simple subtraction (-):
=TODAY()-D2
I made an updated copy of #DrCord’s sample spreadsheet to illustrate this.
Are you SURE you want DAYS360? That is a specialized function used in the
financial sector to simplify calculations for bonds. It assumes a 360 day
year, with 12 months of 30 days each. If you really want actual days, you'll
lose 6 days each year.
[source]
Since this is the top Google answer for this, and it was way easier than I expected, here is the simple answer. Just subtract date1 from date2.
If this is your spreadsheet dates
A B
1 10/11/2017 12/1/2017
=(B1)-(A1)
results in 51, which is the number of days between a past date and a current date in Google spreadsheet
As long as it is a date format Google Sheets recognizes, you can directly subtract them and it will be correct.
To do it for a current date, just use the =TODAY() function.
=TODAY()-A1
While today works great, you can't use a date directly in the formula, you should referencing a cell that contains a date.
=(12/1/2017)-(10/1/2017) results in 0.0009915716411, not 61.
I used your idea, and found the difference and then just divided by 365 days. Worked a treat.
=MINUS(F2,TODAY())/365
Then I shifted my cell properties to not display decimals.
If you are using the two formulas at the same time, it will not work...
Here is a simple spreadsheet with it working:
https://docs.google.com/spreadsheet/ccc?key=0AiOy0YDBXjt4dDJSQWg1Qlp6TEw5SzNqZENGOWgwbGc
If you are still getting problems I would need to know what type of erroneous result you are getting.
Today() returns a numeric integer value: Returns the current computer system date. The value is updated when your document recalculates. TODAY is a function without arguments.
The following worked for me. Kindly note that TODAY() must NOT be the first argument in the function otherwise it will not work.
=DATEDIF( W2, TODAY(), "d")
Today() does return value in DATE format.
Select your "Days left field" and paste this formula in the field
=DAYS360(today(),C2)
Go to Format > Number > More formats >Custom number format and select the number with no decimal numbers.
I tested, it works, at least in new version of Sheets, March 2015.
Is there a function in Haskell that will allow me to enter component of a date (like a string representation or day month year components) that I can get information from (like day of week, days in a month, etc.)?
I've looked online and it looks like there are a lot of custom libraries, but I'm hoping there's one in the standard prelude library of ghci 10.6.4 that's just not well documented?
Are Data.Time.Calendar and Data.Time.Format in the time library sufficient?
You can parse a string representation of a date and get the length of a month using gregorianMonthLength. Not sure about day of the week, though you could format the date as a string using a format that just displays the week day.
A quick Google search turns up this, which may be what you want. It lets you parse strings representing dates and extract information from them.
You can find the day of the week with mondayStartWeek or sundayStartWeek, depending on whether you think a week starts on Monday, or on Sunday. Both functions are in Data.Time.Calendar.OrdinalDate.
λ> snd $ mondayStartWeek $ fromGregorian 2017 10 3
2
In the above example, the return value is 2, which indicates the second day of the week. Since the function is called mondayStartWeek, Monday is the first day, so 2 corresponds to Tuesday. This is true of October 3, 2017.
A warning regarding week numbers
Both functions return a tuple, where the second element is the week day. As far as I can tell, that should be trustworthy.
The first element, however, is the week number of the year. Be careful with that, because the rules for week numbering are political. If I remember correctly, in USA, week 1 is the week that contains January 1. That's not the case in Denmark, where I live. Here, week 1 is the first week where Thursday falls in the new year. This can mean that December 31 can fall in week 1 of the next year. IIRC, this is the rule for many other European countries. Some years, the American and the European week numbers align, but some years, they don't.