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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date formatting

Status
Not open for further replies.

mccartmd

Programmer
Feb 3, 2003
63
US
Hi:
Have tried a lot of differnt ways. . .but. . .

I have a table field named "thisdatet"
and have its type set to datetime, with a width of 8.
How can I truncate it using the format or imputmask?

Without it is like this: 04/12/2010 09:39:19 AM

Would like it to be: 04/12 09:39 AM

Any help is apprecated.
THX
M
 
There's no built-in function that will do exactly what you want. You can get close to it by executing SET SECONDS OFF. That will hide the number of seconds, but you will still see the year.

The following code will create a character string in the format you want:

Code:
SET SECONDS OFF
SET HOURS TO 12
ltDate = <the datetime from your table>
lcResult = TRANSFORM(DAY(ltDate)) + "/" + ;
  TRANSFORM(MONTH(ltDate)) + " " + TTOC(ltDate, 2)

I'm assuming that, in your example, 4 is the day and 12 is the month. If you are using the American date format, just reverse DAY and MONTH in the above code.

I haven't tested this, but it should be roughly what you need.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Just to add ...

If you want leading zeroes in the day and month, modify my code as follows:

Code:
SET SECONDS OFF
SET HOURS TO 12
ltDate = <the datetime from your table>
lcResult = TRANSFORM(DAY(ltDate)[b], "@L 99"[/b]) + "/" + ;
  TRANSFORM(MONTH(ltDate)[b], "@L 99"[/b]) + " " + TTOC(ltDate, 2)

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro tips, advice, training, consultancy
Custom software for your business
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top