473,406 Members | 2,847 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Timestamp problems...wrong weeks.

Hello,
I'm having a problem with timestamps in postgresql.
I run the following query to pull dates in this format:
WEEK/MONTH/YEAR

However the data says that April 28th 2004 was in week 4 of April and
that April 29th 2004 was in week 5 of april.
This is incorrect.

This is causing my reports to print out incorrect data.
Do you know why this would happen? Am I doing something wrong?

--SQL CODE
SELECT
current_timestamp,
completion_date,
to_char(current_timestamp,'W/MM/YYYY'),
to_char(completion_date,'W/MM/YYYY')
FROM anna_onestop_database_t
WHERE to_char(current_timestamp,'MM/YYYY') =
to_char(completion_date,'MM/YYYY')
AND upper(solution_provider) = 'N0050961' AND status LIKE 'Closed -
Completed'

--RESULTSET
Timestamptz |completion_date |to_char
|to_char
2004-04-29 14:29:47.289369-04|2004-04-28 11:40:35|5/04/2004|4/04/2004
2004-04-29 14:29:47.289369-04|2004-04-29 13:26:34|5/04/2004|5/04/2004
thank you!

Troy Campano
Nov 23 '05 #1
8 1870
On Thu, Apr 29, 2004 at 02:42:49PM -0400, Campano, Troy wrote:

This is causing my reports to print out incorrect data.
Do you know why this would happen? Am I doing something wrong?


I think you may be misunderstanding what "W" means:

week of month (1-5) (The first week starts on the first day of the
month.)

In April 2004, 1 April is Thurs, so

1-7 -> W1
8-14 -> W2
15-21 -> W3
22-28 -> W4
29-30 -> W5 == W1 of May

This is also why 8 May is in week 2 of May, but 7 May is on week 1.

A

--
Andrew Sullivan | aj*@crankycanuck.ca

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #2
On Thu, Apr 29, 2004 at 02:42:49PM -0400, Campano, Troy wrote:

This is causing my reports to print out incorrect data.
Do you know why this would happen? Am I doing something wrong?


I think you may be misunderstanding what "W" means:

week of month (1-5) (The first week starts on the first day of the
month.)

In April 2004, 1 April is Thurs, so

1-7 -> W1
8-14 -> W2
15-21 -> W3
22-28 -> W4
29-30 -> W5 == W1 of May

This is also why 8 May is in week 2 of May, but 7 May is on week 1.

A

--
Andrew Sullivan | aj*@crankycanuck.ca

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #3
Personnaly, I think this use of W is useless -- anybody can dewide the
day of the month by 7. A more appropriate use of W might be for the
week number to start with the first week with ALL dates in the month.
An alternate interpretation might be to start with the first week that
has at least one day in the month. The next issue is do you start the
week on Sunday, Saturday or Monday...

JLL
Andrew Sullivan wrote:
On Thu, Apr 29, 2004 at 02:42:49PM -0400, Campano, Troy wrote:
This is causing my reports to print out incorrect data.
Do you know why this would happen? Am I doing something wrong?

I think you may be misunderstanding what "W" means:

week of month (1-5) (The first week starts on the first day of the
month.)

In April 2004, 1 April is Thurs, so

1-7 -> W1
8-14 -> W2
15-21 -> W3
22-28 -> W4
29-30 -> W5 == W1 of May

This is also why 8 May is in week 2 of May, but 7 May is on week 1.

A

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #4
Personnaly, I think this use of W is useless -- anybody can dewide the
day of the month by 7. A more appropriate use of W might be for the
week number to start with the first week with ALL dates in the month.
An alternate interpretation might be to start with the first week that
has at least one day in the month. The next issue is do you start the
week on Sunday, Saturday or Monday...

JLL
Andrew Sullivan wrote:
On Thu, Apr 29, 2004 at 02:42:49PM -0400, Campano, Troy wrote:
This is causing my reports to print out incorrect data.
Do you know why this would happen? Am I doing something wrong?

I think you may be misunderstanding what "W" means:

week of month (1-5) (The first week starts on the first day of the
month.)

In April 2004, 1 April is Thurs, so

1-7 -> W1
8-14 -> W2
15-21 -> W3
22-28 -> W4
29-30 -> W5 == W1 of May

This is also why 8 May is in week 2 of May, but 7 May is on week 1.

A

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 23 '05 #5
"Campano, Troy" <Tr**********@LibertyMutual.com> writes:
However the data says that April 28th 2004 was in week 4 of April and
that April 29th 2004 was in week 5 of april.
This is incorrect.


This *is* correct according to our published specification for the W
format code:

W week of month (1-5) (The first week starts on the first day of the month.)

Since you haven't defined what behavior you want, it's hard to suggest
alternatives, but have you looked at the WW and IW format codes?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #6
"Campano, Troy" <Tr**********@LibertyMutual.com> writes:
However the data says that April 28th 2004 was in week 4 of April and
that April 29th 2004 was in week 5 of april.
This is incorrect.


This *is* correct according to our published specification for the W
format code:

W week of month (1-5) (The first week starts on the first day of the month.)

Since you haven't defined what behavior you want, it's hard to suggest
alternatives, but have you looked at the WW and IW format codes?

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #7
On Thu, Apr 29, 2004 at 05:06:00PM -0400, Jean-Luc Lachance wrote:
Personnaly, I think this use of W is useless -- anybody can dewide the
day of the month by 7.


I didn't write the definition of the behaviour, I was just explaining
how it actually works.

A

--
Andrew Sullivan | aj*@crankycanuck.ca

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #8
On Thu, Apr 29, 2004 at 05:06:00PM -0400, Jean-Luc Lachance wrote:
Personnaly, I think this use of W is useless -- anybody can dewide the
day of the month by 7.


I didn't write the definition of the behaviour, I was just explaining
how it actually works.

A

--
Andrew Sullivan | aj*@crankycanuck.ca

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: RT | last post by:
If anyone can help that would be great. I¹m trying to format a timestamp from my MySQL table (sessions) Here¹s the code I¹m using: <?php echo date('D,n-j-y h:i:s...
0
by: Bruno Batarelo | last post by:
Greetings for a while I simply can not import properly timestamp data back to database. I dump all databases with mysqldump --opt --all-databases > backup.sql and backup file is correctly...
4
by: Pål Andreassen | last post by:
I'm trying to discover the number of weeks in a given year. As I live in Norway we are using the gregorian calendar. First week of a year is the first week with four days. First day of the week is...
6
by: Robert Schuldenfrei | last post by:
Dear NG, As expected, when I went to implement TIMESTAMP, I failed. With the help of Kevin Yu, I got the 2 code segments at the bottom working using a WHERE clause that checks all columns. ...
2
by: Brian | last post by:
NOTE ALSO POSTED IN microsoft.public.dotnet.framework.aspnet.buildingcontrols I have solved most of my Server Control Collection property issues. I wrote an HTML page that describes all of the...
0
by: Campano, Troy | last post by:
Hello, I'm having a problem with timestamps in postgresql. I run the following query to pull dates in this format: WEEK/MONTH/YEAR However the data says that April 28th 2004 was in week 4 of...
4
by: mghale | last post by:
I have a question that I'm hoping has an easy answer. I'm working in DB2 V8.2 on AIX 5.3 I have a timestamp column (i.e. 4/26/2006 1:02:42.000000 PM) that I want to return in a report from...
6
by: bg_ie | last post by:
Hi, I wish to write a C program which obtains the system time and hence uses this time to print out its ntp equivalent. Am I right in saying that the following is correct for the seconds part...
10
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.