<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Date conversion directly in CDS View entity in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929977#M2037779</link>
    <description>&lt;P&gt;Hi Guido, yes Prince fan, well seen, what culture&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have seen the Date functions (DATS_ADD_DAYS, DATS_ADD_MONTHS...) but how can I use them in my context?&lt;/P&gt;&lt;P&gt;If I take the date 10/10/2024 the conversion should give 09/30/2024 as a result, very good but how can I do this in a CDS. I know that to get this result I would have to subtract 10 days from my date 10/10/2024 but how can I calculate these 10 days, save this variable and apply it to DATS_ADD_DAYS(myDate,-10,'NULL')&lt;/P&gt;&lt;P&gt;It seems difficult to me to do operations individually by day/month/year because the problem of changing the year and/or leap year arises.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Nov 2024 10:30:07 GMT</pubDate>
    <dc:creator>tafkap95</dc:creator>
    <dc:date>2024-11-06T10:30:07Z</dc:date>
    <item>
      <title>Date conversion directly in CDS View entity</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929590#M2037766</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I want to change the value of a Date field directly in my CDS View; I want to convert this value to the last day of the previous month. It seems very simple as a need but in CDS View I have trouble &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I tried to use the functions dats_add_months, dats_add_days, combined with cast and substring but I always run into compilation problems, in short I can't do it, in pure ABAP it would take a few seconds &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I was suggested to possibly go through an AMDP function, what do you think?&lt;/P&gt;&lt;P&gt;For example if I have the value 20241015, the converted value will be 20240930, if I have the value 20240123 the converted value will be 20231231.&lt;/P&gt;&lt;P&gt;Thank you very much for your help.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 02:15:46 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929590#M2037766</guid>
      <dc:creator>tafkap95</dc:creator>
      <dc:date>2024-11-06T02:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion directly in CDS View entity</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929712#M2037770</link>
      <description>&lt;P&gt;Hi tafkap (prince fan?),&lt;/P&gt;&lt;P&gt;it would be helpful to know what code you exactly tried to use and which error you received.&lt;/P&gt;&lt;P&gt;Have you seen the post &lt;A href="https://community.sap.com/t5/enterprise-resource-planning-blogs-by-members/cds-view-add-days-to-date/ba-p/13411153" target="_self"&gt;CDS View: Add days to Date?&lt;/A&gt; Here's explained how to use &lt;STRONG&gt;DATS_ADD_DAYS(date,days,on_error)&lt;/STRONG&gt; and how to convert the parameter values.&lt;/P&gt;&lt;P&gt;Guido&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 06:14:55 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929712#M2037770</guid>
      <dc:creator>guido_s</dc:creator>
      <dc:date>2024-11-06T06:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion directly in CDS View entity</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929907#M2037775</link>
      <description>&lt;P&gt;So you need to subtract the day value from the date, look at following built in functions&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A class="" href="https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abensql_date_func.htm#!ABAP_VARIANT_4@4@" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;EXTRACT_DAY( date&lt;I&gt;|&lt;/I&gt;utclong )&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A class="" href="https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/abensql_date_func.htm#!ABAP_VARIANT_9@9@" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;ADD_DAYS(&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;{&lt;/I&gt;date&lt;I&gt;|&lt;/I&gt;utclong&lt;I&gt;}&lt;/I&gt;,days )&lt;/SPAN&gt;&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Or post the code you've already tried.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 09:37:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929907#M2037775</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2024-11-06T09:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion directly in CDS View entity</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929977#M2037779</link>
      <description>&lt;P&gt;Hi Guido, yes Prince fan, well seen, what culture&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I have seen the Date functions (DATS_ADD_DAYS, DATS_ADD_MONTHS...) but how can I use them in my context?&lt;/P&gt;&lt;P&gt;If I take the date 10/10/2024 the conversion should give 09/30/2024 as a result, very good but how can I do this in a CDS. I know that to get this result I would have to subtract 10 days from my date 10/10/2024 but how can I calculate these 10 days, save this variable and apply it to DATS_ADD_DAYS(myDate,-10,'NULL')&lt;/P&gt;&lt;P&gt;It seems difficult to me to do operations individually by day/month/year because the problem of changing the year and/or leap year arises.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 10:30:07 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929977#M2037779</guid>
      <dc:creator>tafkap95</dc:creator>
      <dc:date>2024-11-06T10:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion directly in CDS View entity</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929990#M2037782</link>
      <description>&lt;P&gt;&lt;SPAN&gt;With date 10/10/2024 (MM/DD/YYYY) EXTRACT_DAY will return 10, the ADD_DAYS with days = minus 10 will return 09/30/2024&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 10:43:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13929990#M2037782</guid>
      <dc:creator>RaymondGiuseppi</dc:creator>
      <dc:date>2024-11-06T10:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion directly in CDS View entity</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13930007#M2037785</link>
      <description>&lt;P&gt;Hi tafkap,&lt;/P&gt;&lt;P&gt;to calculate the last day of the previous month you can try this (aedat is the given date):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;DATS_ADD_DAYS( cast( concat( SUBSTRING (aedat,1,6), '01' ) as abap.dats ),-1,'NULL') as last_day_prev_month&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Full example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="abap"&gt;@AbapCatalog.sqlViewName: 'ZFI_V_TST'
@AbapCatalog.compiler.compareFilter: true
@AbapCatalog.preserveKey: true
@AccessControl.authorizationCheck: #CHECK
@EndUserText.label: 'Test'
define view ZFI_CV_TST as select from prps {
  aedat,
  DATS_ADD_DAYS( cast( concat( SUBSTRING (aedat,1,6), '01' ) as abap.dats ),-1,'NULL') as last_day_prev_month
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Nov 2024 08:13:53 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13930007#M2037785</guid>
      <dc:creator>guido_s</dc:creator>
      <dc:date>2024-11-08T08:13:53Z</dc:date>
    </item>
    <item>
      <title>Re: Date conversion directly in CDS View entity</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13930306#M2037790</link>
      <description>&lt;P&gt;Hello Guido, it works perfectly, a huge thank you for your help&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":hugging_face:"&gt;🤗&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Your idea is perfect: you position yourself on the 1st day of the date then you apply -1 day.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2024 14:24:16 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/date-conversion-directly-in-cds-view-entity/m-p/13930306#M2037790</guid>
      <dc:creator>tafkap95</dc:creator>
      <dc:date>2024-11-06T14:24:16Z</dc:date>
    </item>
  </channel>
</rss>

