FoxPro Programming
Converting SQL date field
Gravatar is a globally recognized avatar based on your email address. Converting SQL date field
  Jukka Salminen
  All
  Mar 25, 2025 @ 03:41am

When I query a date field from SQL server I get it as 2008-12-31. Is there a VFP function to convert this to a string like 31.12.2008?

Gravatar is a globally recognized avatar based on your email address. re: Converting SQL date field
  Tore Bleken
  Jukka Salminen
  Mar 25, 2025 @ 10:23am

This code will do the job, but you may have to adjust it to match your settings.

?Chrtran(Transform(ldDate,"@YS"),'-','.')
Gravatar is a globally recognized avatar based on your email address. re: Converting SQL date field
  Tore Bleken
  Jukka Salminen
  Mar 25, 2025 @ 10:23am

This code will do the job, but you may have to adjust it to match your settings.

?Chrtran(Transform(ldDate,"@YS"),'-','.')
Gravatar is a globally recognized avatar based on your email address. re: Converting SQL date field
  Rick Strahl
  Jukka Salminen
  Mar 25, 2025 @ 10:24am

When you query a date from SQL Server you should get back a FoxPro date. The date has no format until you turn it into a string.

FoxPro will format dates into the culture specific format using TRANSFORM(ldDate) and the format you see likely is your local culture's date format. AFAIK you can't change the way that works via native functions.

In Web Connection/Client Tools there are functions for FormatValue() where you can specify a date string like you want:

Using that you could use:

? FormatValue(ltDate, "MM.dd.yyyy")

There's also FormatString() which lets you inject the value into a formatted string:

+++ Rick ---

© 1996-2025