Solved

AS400 DAYOFWEEK(GENERAL DATE)

Posted on 2015-02-05
12
362 Views
Last Modified: 2015-02-07
Hi,

I want to use the DAYOFWEEK Function in an AS400 SQL call.  The date is currently  = 42041 (2/6/2015 or 20150206).

How can I use the DAYOFWEEK Function with this date format?

Otherwise how do I convert 42041 to 20150206?

Also is my terminology for 42041 (General Date) correct?  What should it be?

Thanks
0
Comment
Question by:adb11a
  • 4
  • 4
  • 3
12 Comments
 
LVL 18

Expert Comment

by:daveslash
ID: 40592591
How does 2015-02-06 translate to 42041 ?
0
 

Author Comment

by:adb11a
ID: 40592603
OBRGDT = 20150206

DAYS(DATE(SUBSTR(OBRGDT,1,4)||'-'||SUBSTR(OBRGDT,5,2)||'-'||SUBSTR(OBRGDT,7,2))) AS OBRGDT_1

You may ask why I don't just use OBRGDT but it is too long a story (presenting data in Excel).

My other option is to convert 42041 to 20150206 if you know how to do that?
0
 

Author Comment

by:adb11a
ID: 40592605
Sorry daveslash, should have READ:

CASE WHEN OBRGDT = 0 THEN 0  ELSE DAYS(DATE(SUBSTR(OBRGDT,1,4)||'-'||SUBSTR(OBRGDT,5,2)||'-'||SUBSTR(OBRGDT,7,2))) - DAYS('1/1/1900') + 2 END
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40592612
As you refer to DAYOFWEEK I'm assuming you are using DB2 so I'd like to propose this article for reading

DB2 Basics: Fun with Dates and Times

It has numerous examples of how date/times and related functions work in DB2,  including  current date

but I don't understand "The date is currently  = 42041"
0
 

Author Comment

by:adb11a
ID: 40592632
If you open excel, type '=TODAY()', press enter then format the cell as 'General' you'll get 42041.

I need the date in this format for formatting purposes in Excel.  I just need to be able to either convet 42041 to 20150206 or use DAYOFWEEK(42041).

I looked at the site you showed me and no luck.  Still looking
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 48

Expert Comment

by:PortletPaul
ID: 40592659
I'm confused.
Are you performing this calculation in DB2 (where you can use DAYOFWEEK)
or in Excel (where you can use WEEKDAY)
?

e.g. In Excel
=WEEKDAY(TODAY())

and
Excel will accept dates (e.g. 31/12/1900 or 12/31/1900 etc.) depending on your locale settings


If in DB2 you would pass a timestamp field into the function

SELECT DAYOFWEEK(current date)  FROM sysibm.sysdummy1

{+edit, a correction; incorrect use of weekday in line above}
0
 
LVL 18

Accepted Solution

by:
daveslash earned 300 total points
ID: 40592661
Thank you for the learning experience. I never knew you could represent a DATE like that.

This works for me:

select date(42039 + days('1900-01-01')), 
       dayOfWeek(date(42039 + days('1900-01-01')))
  from sysibm.sysdummy1

DATE            DAYOFWEEK
2015-02-06              6

Open in new window


HTH,
DaveSlash
0
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 200 total points
ID: 40592664
oh and "day zero" in Excel is 1900-12-31, add 42041 days to that and you arrive at 2015-02-06

i.e. enter 0 into cell now format that cell as a date in another cell add 42041 to that 0
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40592667
Excellent work! (learning experience for me also)

Cheers.

sorry for the cross posting, can be a bit confusing
0
 
LVL 18

Expert Comment

by:daveslash
ID: 40594952
adb11a: did that solve your problem?
0
 

Author Comment

by:adb11a
ID: 40595357
Hi deveslash.

Your suggestion of:

select date(42039 + days('1900-01-01')),
       dayOfWeek(date(42039 + days('1900-01-01')))
  from sysibm.sysdummy1

works for me.

Thanks and thanks to PortletPaul.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Installing a Printer on AS400 5 168
Connect SQL Developer to zO/S DB2 database 6 227
ODBC connect from ms access to DB2 3 75
iSeries DB2 query across local and remote site 4 66
Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now