PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, December 19, 2022

[FIXED] How to use DateAdd function in Crystal Reports while in Basic Syntax mode

 December 19, 2022     basic, crystal-reports, syntax     No comments   

Issue

I have a formula in Crystal Reports that is written in Basic Syntax in order for it to be used with the HTML text interpretation. In one part of the code, I would like to add six months to Today's date. I know the DateAdd function can do this but I keep getting an error stating that a date is required. I know that the DateAdd function works without any problems in Crystal Syntax Mode, but I need to remain in Basic Syntax mode in order for the other code in the formula to work. What is the proper way to use DateAdd in Basic Syntax mode in Crystal Reports?

I tried using code similar to this:

dim sdate as date 
sdate = DateAdd("m", 6, Today) 
formula = sdate

When I try to save it, it returns an error and highlights the DateAdd function and the arguments ("DateAdd("m", 6, Today") and says

"A date is required here."


Solution

The DateAdd function returns a DateTime, but sdate is declared as Date.

So there are two possibilities:

  1. If the time part is required, declare sdate as DateTime and use CurrentDateTime instead of Today :

    Dim sdate As DateTime
    sdate = DateAdd("m", 6, CurrentDateTime)
    formula = sdate
    
  2. If the time part is not required, convert the result of DateAdd to Date :

    Dim sdate As Date
    sdate = CDate(DateAdd("m", 6, Today))
    formula = sdate
    


Answered By - MatSnow
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing