<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Writing a Date expression in PS Query</title>
		<link>http://www.peoplesoftwiki.com/forum/t-129686/writing-a-date-expression-in-ps-query</link>
		<description>Posts in the discussion thread &quot;Writing a Date expression in PS Query&quot;</description>
				<copyright></copyright>
		<lastBuildDate>Fri, 30 Jul 2010 05:06:33 +0000</lastBuildDate>
		
					<item>
				<guid>http://www.peoplesoftwiki.com/forum/t-129686#post-569824</guid>
				<title>Re: Writing a Date expression in PS Query</title>
				<link>http://www.peoplesoftwiki.com/forum/t-129686/writing-a-date-expression-in-ps-query#post-569824</link>
				<description></description>
				<pubDate>Wed, 26 Aug 2009 05:20:04 +0000</pubDate>
				<wikidot:authorName>Praj</wikidot:authorName>				<wikidot:authorUserId>52320</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Here's an example that's similar to yours that may help.</p> <p>Find all user profiles that were updated in the last year.</p> <p>To do this in SQL:</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">OPRID</span><span class="hl-code">, </span><span class="hl-identifier">LASTUPDDTTM</span><span class="hl-code"> </span><span class="hl-reserved">from</span><span class="hl-code"> </span><span class="hl-identifier">PSOPRDEFN</span><span class="hl-code"> </span><span class="hl-reserved">where</span><span class="hl-code"> </span><span class="hl-identifier">LASTUPDDTTM</span><span class="hl-code"> </span><span class="hl-var">between</span><span class="hl-code"> </span><span class="hl-brackets">(</span><span class="hl-identifier">sysdate</span><span class="hl-code"> - </span><span class="hl-number">365</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">and</span><span class="hl-code"> </span><span class="hl-identifier">sysdate</span><span class="hl-code"> </span><span class="hl-reserved">order</span><span class="hl-code"> </span><span class="hl-reserved">by</span><span class="hl-code"> </span><span class="hl-identifier">LASTUPDDTTM</span><span class="hl-code"> </span><span class="hl-reserved">desc</span><span class="hl-code">;</span> </pre></div> </div> <p>So find any user where the last update date/time <tt>LASTUPDDTTM</tt> is greater than or equal to 365 days (1 year) back from the current date, up until the current date.</p> <p>Here's how you would create this expression in PS Query.</p> <table class="wiki-content-table"> <tr> <td><img src="http://peoplesoft.wikidot.com/local--files/images/date-between-one-year-period.png" alt="date-between-one-year-period.png" class="image" /></td> </tr> </table> <p>Note that I've replaced <tt>sysdate</tt> with meta-SQL - <tt>%CurrentDateTimeIn</tt> and <tt>%AddDate(%CurrentDateTimeIn, -365)</tt> to go back 365 days.</p> <p>For the second part, you might want count all user profiles that were updated in the last year, grouped by each month. Here's the SQL you would write to do this:</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-reserved">select</span><span class="hl-code"> </span><span class="hl-identifier">to_char</span><span class="hl-brackets">(</span><span class="hl-identifier">LASTUPDDTTM</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">Month</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">as</span><span class="hl-code"> </span><span class="hl-reserved">MONTH</span><span class="hl-code">, </span><span class="hl-var">count</span><span class="hl-brackets">(</span><span class="hl-reserved">distinct</span><span class="hl-code"> </span><span class="hl-identifier">OPRID</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">from</span><span class="hl-code"> </span><span class="hl-identifier">PSOPRDEFN</span><span class="hl-code"> </span><span class="hl-reserved">where</span><span class="hl-code"> </span><span class="hl-identifier">LASTUPDDTTM</span><span class="hl-code"> &gt;= </span><span class="hl-brackets">(</span><span class="hl-identifier">sysdate</span><span class="hl-code"> - </span><span class="hl-number">365</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">and</span><span class="hl-code"> </span><span class="hl-identifier">LASTUPDDTTM</span><span class="hl-code"> &lt;= </span><span class="hl-identifier">sysdate</span><span class="hl-code"> </span><span class="hl-reserved">group</span><span class="hl-code"> </span><span class="hl-reserved">by</span><span class="hl-code"> </span><span class="hl-identifier">to_char</span><span class="hl-brackets">(</span><span class="hl-identifier">LASTUPDDTTM</span><span class="hl-code">, </span><span class="hl-quotes">'</span><span class="hl-string">Month</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code">;</span> </pre></div> </div> <p>The key here is the use of to_char to convert the month part of the <tt>LASTUPDDTTM</tt> field to a month. Here's how you would create the expression:</p> <table class="wiki-content-table"> <tr> <td><img src="http://peoplesoft.wikidot.com/local--files/images/to-month-expression.png" alt="to-month-expression.png" class="image" /></td> </tr> </table> <p>Add this as a field, and perform a count on the <tt>OPRID</tt> field.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://www.peoplesoftwiki.com/forum/t-129686#post-565869</guid>
				<title>Re: Writing a Date expression in PS Query</title>
				<link>http://www.peoplesoftwiki.com/forum/t-129686/writing-a-date-expression-in-ps-query#post-565869</link>
				<description></description>
				<pubDate>Fri, 21 Aug 2009 09:15:01 +0000</pubDate>
				<wikidot:authorName>john</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>I am using PSquery to calculate the number of people who have send their resume to the company within a year period. How could I do that using date format in PSQuery?</p> <p>also the number of resume received at the 31 of each month….</p> <p>Thanks for your help</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://www.peoplesoftwiki.com/forum/t-129686#post-388965</guid>
				<title>Re: Writing a Date expression in PS Query</title>
				<link>http://www.peoplesoftwiki.com/forum/t-129686/writing-a-date-expression-in-ps-query#post-388965</link>
				<description></description>
				<pubDate>Wed, 18 Feb 2009 17:53:09 +0000</pubDate>
				<wikidot:authorName>Steve</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Hi,</p> <p>Sorry it's taken me a few days to reply.</p> <p>I couldn't get PSQuery to insert this expression without all the other associated code. I gave up in the end and ran it directly against the database via SQL. The end user only wanted a one report so it wasn't too much of a problem.</p> <p>Thanks for you assistance.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://www.peoplesoftwiki.com/forum/t-129686#post-383834</guid>
				<title>Re: Writing a Date expression in PS Query</title>
				<link>http://www.peoplesoftwiki.com/forum/t-129686/writing-a-date-expression-in-ps-query#post-383834</link>
				<description></description>
				<pubDate>Fri, 13 Feb 2009 04:49:36 +0000</pubDate>
				<wikidot:authorName>Praj</wikidot:authorName>				<wikidot:authorUserId>52320</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hi,</p> <p>I can't seem to be able to replicate your scenario where the expression you're using as a field:</p> <p><tt>to_char(round(a.effdt - A.LASTUPDDTTM))</tt></p> <p>Suddenly turns to:</p> <p><tt>to_char(round( TO_CHAR(A.EFFDT,'YYYY-MM-DD') - TO_CHAR(CAST((A.LASTUPDDTTM) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF')))</tt></p> <p>In the View SQL tab. Are you using any criteria on your expression field? Can you try removing all fields in your query, then going to the expressions tab, finding your expression and selecting use as a field again?</p> <p>Sometimes PS Query caches the expression and you get the wrong version of it. It <em>should</em> put the expression exactly in line into your SQL.</p> <p>Another thing you can try is:</p> <ul> <li>Create a new private query</li> <li>Add the record PSXLATITEM</li> <li>Select the fields, FIELDNAME, FIELDVALUE, EFFDT, LASTUPDDTTM</li> <li>Create a new expression: <tt>to_char(round(LASTUPDDTTM - EFFDT)) DAYS</tt> as a character with a length of 15 and choose select use as field to make it the fifth field.</li> <li>Have a look at your view SQL and see if that looks right/runs? You might get a maximum rows exceeded error but that's ok, the field should show the number of days.</li> </ul> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://www.peoplesoftwiki.com/forum/t-129686#post-382909</guid>
				<title>Re: Writing a Date expression in PS Query</title>
				<link>http://www.peoplesoftwiki.com/forum/t-129686/writing-a-date-expression-in-ps-query#post-382909</link>
				<description></description>
				<pubDate>Thu, 12 Feb 2009 08:23:55 +0000</pubDate>
				<wikidot:authorName>Steve</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Thanks for your reply it's appreciated :).</p> <p>I've modified your expression above to use my field names, it looks as follows:-</p> <p>to_char(round(a.effdt - A.LASTUPDDTTM))</p> <p>I've set the expression type to character and the length to 15. When I run it I receive the following error:-</p> <p>A SQL error occurred. Please consult your system log for details.<br /> Error in running query because of SQL Error, Code=1722, Message=ORA-01722: invalid number (50,380)</p> <p>When I look at the SQL that's been inserted by PSQUERY (View SQL Tab) i see the following for this expression:-</p> <p>to_char(round( TO_CHAR(A.EFFDT,'YYYY-MM-DD') - TO_CHAR(CAST((A.LASTUPDDTTM) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF'))),</p> <p>Any more ideas gratefully received, it's driving me mad. Especially as when you do the same line in SQL it works fine.</p> <p>Thanks<br /> Steve</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://www.peoplesoftwiki.com/forum/t-129686#post-382777</guid>
				<title>Re: Writing a Date expression in PS Query</title>
				<link>http://www.peoplesoftwiki.com/forum/t-129686/writing-a-date-expression-in-ps-query#post-382777</link>
				<description></description>
				<pubDate>Thu, 12 Feb 2009 03:41:14 +0000</pubDate>
				<wikidot:authorName>Praj</wikidot:authorName>				<wikidot:authorUserId>52320</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hi,</p> <p>I have written something similar in PS Query to return the processing time for a process/job in the process request table. This query returns the process instance, process name, operator ID, run status, run control ID and processing time (which is process end date/time - process begin date/time expressed as seconds).</p> <p>What you have explained is very close. My processing time expression looks like this:</p> <img src="http://peoplesoft.wikidot.com/local--files/forum:thread/processing-time-query-expression.png" alt="processing-time-query-expression.png" class="image" /> <p>You can ignore the case statement, the key to this is really the following:</p> <p><tt>to_char(round((ENDDTTM - BEGINDTTM) * 24 * 60 * 60))</tt></p> <p>This gives the difference in seconds. However if you just want the answer in days it would be just:</p> <p><tt>to_char(round(ENDDTTM - BEGINDTTM))</tt></p> <p>Which is pretty much exactly what you have. Note the <tt>to_char</tt> is to format the output in character format which PSQuery seems to handle a lot better than numeric format.</p> <p>In terms of formatting instead of messing around with dates I've just used a character expression as I just want to display the number of seconds. I figure you just want the output as the number of days?</p> <p>My Query SQL looks like this:</p> <div class="code"> <div class="hl-main"> <pre> <span class="hl-reserved">SELECT</span><span class="hl-code"> </span><span class="hl-identifier">A</span><span class="hl-code">.</span><span class="hl-identifier">PRCSINSTANCE</span><span class="hl-code"> , </span><span class="hl-identifier">A</span><span class="hl-code">.</span><span class="hl-identifier">PRCSNAME</span><span class="hl-code"> , </span><span class="hl-identifier">TO_CHAR</span><span class="hl-brackets">(</span><span class="hl-identifier">A</span><span class="hl-code">.</span><span class="hl-identifier">RUNDTTM</span><span class="hl-code"> ,</span><span class="hl-quotes">'</span><span class="hl-string">YYYY-MM-DD-HH24.MI.SS."000000"</span><span class="hl-quotes">'</span><span class="hl-brackets">)</span><span class="hl-code"> , </span><span class="hl-identifier">A</span><span class="hl-code">.</span><span class="hl-identifier">OPRID</span><span class="hl-code"> , </span><span class="hl-identifier">A</span><span class="hl-code">.</span><span class="hl-identifier">RUNSTATUS</span><span class="hl-code"> , </span><span class="hl-identifier">A</span><span class="hl-code">.</span><span class="hl-identifier">RUNCNTLID</span><span class="hl-code"> , </span><span class="hl-brackets">(</span><span class="hl-reserved">CASE</span><span class="hl-code"> </span><span class="hl-reserved">WHEN</span><span class="hl-code"> </span><span class="hl-identifier">ENDDTTM</span><span class="hl-code"> </span><span class="hl-reserved">IS</span><span class="hl-code"> </span><span class="hl-reserved">NULL</span><span class="hl-code"> </span><span class="hl-reserved">THEN</span><span class="hl-code"> </span><span class="hl-quotes">'</span><span class="hl-string">Not Available</span><span class="hl-quotes">'</span><span class="hl-code"> </span><span class="hl-reserved">ELSE</span><span class="hl-code"> </span><span class="hl-identifier">to_char</span><span class="hl-brackets">(</span><span class="hl-identifier">round</span><span class="hl-brackets">((</span><span class="hl-identifier">ENDDTTM</span><span class="hl-code"> - </span><span class="hl-identifier">BEGINDTTM</span><span class="hl-brackets">)</span><span class="hl-code"> * </span><span class="hl-number">24</span><span class="hl-code"> * </span><span class="hl-number">60</span><span class="hl-code"> * </span><span class="hl-number">60</span><span class="hl-brackets">))</span><span class="hl-code"> </span><span class="hl-reserved">END</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-reserved">AS</span><span class="hl-code"> </span><span class="hl-identifier">PROCESSING_TIME</span><span class="hl-code"> </span><span class="hl-reserved">FROM</span><span class="hl-code"> </span><span class="hl-identifier">PSPRCSRQST</span><span class="hl-code"> </span><span class="hl-identifier">A</span> </pre></div> </div> <p>If you try to get the output in date format you'll have all kinds of problems. For example what do you display as the year and month? What about the timestamp? I've found that I really just want the difference expressed as a year, month, day, hour, minute or second value and not in date format at all.</p> <p>Hope that helps.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://www.peoplesoftwiki.com/forum/t-129686#post-382437</guid>
				<title>Writing a Date expression in PS Query</title>
				<link>http://www.peoplesoftwiki.com/forum/t-129686/writing-a-date-expression-in-ps-query#post-382437</link>
				<description></description>
				<pubDate>Wed, 11 Feb 2009 20:17:44 +0000</pubDate>
				<wikidot:authorName>Steve</wikidot:authorName>								<content:encoded>
					<![CDATA[
						 <p>Hi,</p> <p>I'm trying to write an expression in PSQuery which will subtract two dates from each other and return the difference.</p> <p>If I write the following in SQL it works fine, Select ROUND(A.EFFDT - A.LASTUPDDTTM) from PS_JOB a.</p> <p>However if I try to insert this as an expression in PSQuery I get various error messages about Date formats beingincorrect.</p> <p>I think the problem is the dynamic SQL that's created by PSQuery, i tried added a To_Date conversion into the expression but PS still wirting the SQL as follows:-</p> <p>SELECT TO_DATE( TO_CHAR(A.EFFDT,'YYYY-MM-DD'),'YYYY-MM-DD') - (TO_DATE( TO_CHAR(CAST((A.LASTUPDDTTM) AS TIMESTAMP),'YYYY-MM-DD-HH24.MI.SS.FF'),'YYYY-MM-DD-HH24-MI-SS-FF'))</p> <p>If I don't include the .SS.FF in the mask I receive an error about the date picture, ORA1830 error.</p> <p>Does anybody have any experience of using the last update field on job in HRMS. Or can anybody suggest how I can write the expression in ps query.</p> <p>Thanks<br /> Steve</p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>