Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

format of dates

Status
Not open for further replies.

kratz

Programmer
Nov 17, 2006
35
US
How should I format a specific date so I can use it in a formula?
 
Do you mean, put it in a text string? You could have something like
Code:
"Date is " & ToText({your.date}, "DD-MMM-yyyy")

Dates can be null, it might be better to do
Code:
if IsNull({your.date}) then "No Date"
else
"Date is " & ToText({your.date}, "DD-MMM-yyyy")



It helps to give your Crystal version - 8, 8.5, 9, 10, 11 or whatever. Methods change between versions, and higher versions have extra options.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Thank you.
No, I was seeking a way to compare a database date to a static date not received as a parameter.
Happily somebody pointed me to DateValue; apparently a static date has to be converted before it can be compared to a db date.
 
A static date needs to be converted... Who makes up this stuff?

A date needs to be converted ONLY if it is NOT a date.

-k
 
Try Cdate({your.field}). That turns a string with date information into something Crystal will then handle as a date.

[yinyang] Madawc Williams (East Anglia, UK). Using Windows XP & Crystal 10 [yinyang]
 
Confidential to synapsevampire ...
In answer to your question ("Who makes up this stuff?) I would like to point out that in SQL+ one can compare db fields directly to a date (like, '01-JAN-07'). Is it really so mystifying that some ignoramous (moi) would marvel that grand-and-glorious Crystal cannot do such a simple thing?
As for your other comment ("A date needs to be converted ONLY if it is NOT a date.") ... did you know that the Dateadd function takes a date as a parameter but returns not a date but a datetime (specifically midnight AM)? Consequently that alleged date does need to be converted (a la Datevalue) to an actual date when that is what's needed.
 
What you are speaking of in SQL is an explicit conversion, and I'm very familiar with it. And some languages support polymorphism.

As for a date changing to a datetime, that's true, what does that have to do with using the term static date?

Static isn't a data type, it is the state of an object, as in static vs dynamic.

Your condescending approach and misunderstanding of basic technical terms doesn't serve your point well, whatever it might be...

-k
 
Oh and Kratz, Crystal will convert strings to a date if it recognizes the formta, try:

date("1-1-1970")

Note this is not called a static date, this is called a string which is formatted as a date. In general, something frowned upon.

-k
 
synapsevampire,
Thank you.

I think I've beaten this dead horse enough. Let's consider this thread closed.
 
Okey dokey smokey, got it, SQL Plus does date conversions (no, the Oracle Server does, SQL plus is a front end tool), and dates stored as strings are now called "static dates".

The smart money's on the dead horse.

-k
 
Just be careful doing string conversions if you report is sent to another PC. They might have different regional settings.

So Date("1-4-2007") might be January for one user and April for another.

I've also uncovered a bug with date literals so be careful with them.

#1/4/2007# is April here in NZ, but if you use #1/14/2007# in the same report on the same machine it switches to January.

Editor and Publisher of Crystal Clear
 
To handle the Regional settings issue the Static date can be referenced using Cdate(year,month,day)

An example for January 4th 2007:

Cdate(2007,1,4)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top