Re: How to convert data/time to string in query?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You can do that with the Format function. However, if your purpose is to
extract a part of the date, you can do that in a more locale-independent way
using the various functions designed for that purpose, such as Year(),
Month(), Day(), etc.

Here's an example that on my system (where short date format includes
four-digit years) returns the same value in both columns (albeit one is a
string and the other is an integer). The first column might return a
different result on another system, the second column would not ...

SELECT Right$(Format$([OrderDate],"Short Date"),4) AS StringDate,
Year([OrderDate]) AS OrderYear
FROM dbo_Orders;

--
Brendan Reynolds (MVP)

"Frank Xia" <FrankXia@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:E224A9CD-0DA7-44B4-9D44-286031B0F858@xxxxxxxxxxxxxxxx
> How to convert date/time to string in query? So I can handle it with using
> "Left" or "Right" function.
>
> Thanks for any help in advance!


.



Relevant Pages

  • Re: How to convert data/time to string in query?
    ... "Brendan Reynolds" wrote: ... > You can do that with the Format function. ... if your purpose is to ... > string and the other is an integer). ...
    (microsoft.public.access.conversion)
  • Re: Audit Trail for records
    ... Alias "GetComputerNameA" (ByVal lpBuffer As String, ... 'Purpose: Create a log entry for the form/report being opened. ... rs!DocName = strDoc ... Private Function CurViewAs Variant ...
    (microsoft.public.access.forms)
  • Re: Audit Trail for records
    ... Alias "GetComputerNameA" (ByVal lpBuffer As String, ... 'Purpose: Create a log entry for the form/report being opened. ... rs!DocName = strDoc ... Private Function CurViewAs Variant ...
    (microsoft.public.access.forms)
  • Re: How Do I parse this XML document, most efficiently?
    ... The purpose of that line is to get a string that can be used to perform fast ... reference comparison against the current LocalName, ... >> // Move to root element ...
    (microsoft.public.dotnet.xml)
  • Using INI API for progress logging
    ... ' Purpose: ... Public Property Get AppIniFileNameAs String ... Delete the specified section from this application's .INI file. ... ' Function: IniGetBool() ...
    (microsoft.public.vb.general.discussion)