NetTalk Central

Author Topic: Coding a date field to be a particular day date  (Read 2530 times)

Richard I

  • Sr. Member
  • ****
  • Posts: 416
    • View Profile
    • Email
Coding a date field to be a particular day date
« on: March 18, 2025, 08:49:54 PM »
I want to change a date in a month by code  say 23/07/2024 to 01/07/2024

In the table there could be a range of dates and I want them all to become the first of the respective month and year
Thanks

Cheers
Richard

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 444
    • View Profile
    • Email
Re: Coding a date field to be a particular day date
« Reply #1 on: March 18, 2025, 10:27:52 PM »
Maybe something like this

NewDate = DATE(MONTH(OriginalDate),1,YEAR(OriginalDate))

Richard I

  • Sr. Member
  • ****
  • Posts: 416
    • View Profile
    • Email
Re: Coding a date field to be a particular day date
« Reply #2 on: March 18, 2025, 11:05:48 PM »
Thanks for that Niels, I need it in the format dd/mm/yyyy
I think your expression will return mm/dd/yyyy ?
Could then  format newdate as  @0D6 ?
Would that work?
Cheers,
Richard

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 444
    • View Profile
    • Email
Re: Coding a date field to be a particular day date
« Reply #3 on: March 18, 2025, 11:19:20 PM »
format(DATE(MONTH(OriginalDate),1,YEAR(OriginalDate)),@D06)

Richard I

  • Sr. Member
  • ****
  • Posts: 416
    • View Profile
    • Email
Re: Coding a date field to be a particular day date
« Reply #4 on: March 19, 2025, 12:40:34 AM »
Thanks but no not yet!

Niels Larsen

  • Sr. Member
  • ****
  • Posts: 444
    • View Profile
    • Email
Re: Coding a date field to be a particular day date
« Reply #5 on: March 19, 2025, 01:27:18 AM »
You should be aware that FORMAT returns a string and not a date.
A date in Clarion is represented as number of days elapsed since December 28, 1800.
What you are trying will not work.
You should remove FORMAT from your import and only use it when data is to be displayed on the screen or in a report (or exported in a csv file)

Richard I

  • Sr. Member
  • ****
  • Posts: 416
    • View Profile
    • Email
Re: Coding a date field to be a particular day date
« Reply #6 on: March 23, 2025, 08:43:38 PM »
Thanks Niels for the heads up  re "DAY"
FYI
The Code is now sorted , provided the date column in the CSV file is changed to dd/mm/yyyy

herewith for your interest

        SET(Lineitems)
        Access:Lineitems.usefile
        OPEN (Lineitems)
        Relate:ImportCSV.OPEN
        SET(ImportCSV)
        LOOP until Access:ImportCSV.Next()
        Lin:UserName  = p_web.GSV('Username')
        Lin:Quantity      = 1
        Lin:Product        =  ImpCSV:Label3                                             
        Lin:Price             =  ImpCSV:Label6
        Lin:IncomeItem  = 0
        IF Lin:Price > 1 THEN  Lin:IncomeItem  = 1 END
        IF LIN:Price < 1 THEN LIN:Price = (LIN:Price * -1 ) END
        Lin:Total              = Lin:Price
        Lin:date                = deformat( ImpCSV:Label7),@D6)
        locNewDate        = LIN:Date 
        locdaydate          =   DAY(Lin:Date)   
        LIN:Date              =   (locNewDate - locdaydate) +1   
        INV:Date =    Lin:date   
        IF access:Invoice.Fetch(INV:byDateDescending) = LEVEL:Benign
            Lin:InvoiceNumber = INV:ID
        END
        Access:LineItems.Insert()     
        END
  loc:Alert = 'Your Bank Statement has been Imported.'

Regards,
Richard
« Last Edit: March 23, 2025, 08:45:32 PM by Richard I »