Microsoft Office Forums


Reply
Thread Tools Display Modes

Convert date to string?

 
 
Emjaysea
Guest
Posts: n/a
 
      10-09-2007, 09:04 PM
I have month, day, and year variables for some records but not for others
(appropriately). I need to create an expression that will return a date
value or a string version of that value if those are populated and a null or
a blank string if they aren't. I can convert to a date or a string with that
date, but I always get #Error when there is not a valid date.

Here's one version of what I've tried so far. Any ideas? Thanks.

apptdate:
IIf(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy])),CStr(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy]))),"")
 
Reply With Quote
 
 
 
 
UpRider
Guest
Posts: n/a
 
      10-09-2007, 09:28 PM
Take a look in help for the IsDate function.
UpRider

"Emjaysea" <(E-Mail Removed)> wrote in message
newsEEC5737-78E2-42C0-9312-(E-Mail Removed)...
>I have month, day, and year variables for some records but not for others
> (appropriately). I need to create an expression that will return a date
> value or a string version of that value if those are populated and a null
> or
> a blank string if they aren't. I can convert to a date or a string with
> that
> date, but I always get #Error when there is not a valid date.
>
> Here's one version of what I've tried so far. Any ideas? Thanks.
>
> apptdate:
> IIf(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy])),CStr(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy]))),"")



 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      10-09-2007, 11:30 PM
On Tue, 9 Oct 2007 14:04:01 -0700, Emjaysea
<(E-Mail Removed)> wrote:

>I have month, day, and year variables for some records but not for others
>(appropriately). I need to create an expression that will return a date
>value or a string version of that value if those are populated and a null or
>a blank string if they aren't. I can convert to a date or a string with that
>date, but I always get #Error when there is not a valid date.
>
>Here's one version of what I've tried so far. Any ideas? Thanks.
>
>apptdate:
>IIf(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy])),CStr(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy]))),"")


I'd try:

IIF(IsNull([yr]) OR IsNull([mo]) OR IsNull([dy]), Null, DateSerial([yr], [mo],
[dy]))


John W. Vinson [MVP]
 
Reply With Quote
 
Van T. Dinh
Guest
Posts: n/a
 
      10-10-2007, 12:48 AM
.... and another option:

IIf(IsNumeric([yr]) AND IsNumeric([mo] AND IsNumeric([dy]),
DateSerial([yr], [mo], [dy]), Null)

(type as one line in your code.)

--
HTH
Van T. Dinh
MVP (Access)



"Emjaysea" <(E-Mail Removed)> wrote in message
newsEEC5737-78E2-42C0-9312-(E-Mail Removed)...
>I have month, day, and year variables for some records but not for others
> (appropriately). I need to create an expression that will return a date
> value or a string version of that value if those are populated and a null
> or
> a blank string if they aren't. I can convert to a date or a string with
> that
> date, but I always get #Error when there is not a valid date.
>
> Here's one version of what I've tried so far. Any ideas? Thanks.
>
> apptdate:
> IIf(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy])),CStr(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy]))),"")



 
Reply With Quote
 
Pieter Wijnen
Guest
Posts: n/a
 
      10-10-2007, 07:00 AM
Simplified: IIf (IsNull(yr+mo+dy),Null, DateSerial([yr], [mo], [dy]))

no reason not to utilize the "problem" <g>

Pieter


"John W. Vinson" <jvinson@STOP_SPAM.WysardOfInfo.com> wrote in message
news:(E-Mail Removed)...
> On Tue, 9 Oct 2007 14:04:01 -0700, Emjaysea
> <(E-Mail Removed)> wrote:
>
>>I have month, day, and year variables for some records but not for others
>>(appropriately). I need to create an expression that will return a date
>>value or a string version of that value if those are populated and a null
>>or
>>a blank string if they aren't. I can convert to a date or a string with
>>that
>>date, but I always get #Error when there is not a valid date.
>>
>>Here's one version of what I've tried so far. Any ideas? Thanks.
>>
>>apptdate:
>>IIf(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy])),CStr(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy]))),"")

>
> I'd try:
>
> IIF(IsNull([yr]) OR IsNull([mo]) OR IsNull([dy]), Null, DateSerial([yr],
> [mo],
> [dy]))
>
>
> John W. Vinson [MVP]



 
Reply With Quote
 
John W. Vinson
Guest
Posts: n/a
 
      10-10-2007, 04:48 PM
On Wed, 10 Oct 2007 09:00:21 +0200, "Pieter Wijnen"
<it.isi.llegal.to.send.unsollicited.mail.wijnen.no (E-Mail Removed)>
wrote:

>Simplified: IIf (IsNull(yr+mo+dy),Null, DateSerial([yr], [mo], [dy]))
>
>no reason not to utilize the "problem" <g>


<g> Excellent. Simple is good.

John W. Vinson [MVP]
 
Reply With Quote
 
Emjaysea
Guest
Posts: n/a
 
      10-10-2007, 08:08 PM
Thanks to all for your help.

"Van T. Dinh" wrote:

> .... and another option:
>
> IIf(IsNumeric([yr]) AND IsNumeric([mo] AND IsNumeric([dy]),
> DateSerial([yr], [mo], [dy]), Null)
>
> (type as one line in your code.)
>
> --
> HTH
> Van T. Dinh
> MVP (Access)
>
>
>
> "Emjaysea" <(E-Mail Removed)> wrote in message
> newsEEC5737-78E2-42C0-9312-(E-Mail Removed)...
> >I have month, day, and year variables for some records but not for others
> > (appropriately). I need to create an expression that will return a date
> > value or a string version of that value if those are populated and a null
> > or
> > a blank string if they aren't. I can convert to a date or a string with
> > that
> > date, but I always get #Error when there is not a valid date.
> >
> > Here's one version of what I've tried so far. Any ideas? Thanks.
> >
> > apptdate:
> > IIf(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy])),CStr(CDate(DateSerial([tblNV]![yr],[tblNV]![mo],[tblNV]![dy]))),"")

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Val to convert a string JMCS Access Newsgroup 1 08-03-2005 10:12 AM
how to convert string date to be recognized by SQL? Min Access Newsgroup 1 10-09-2004 03:46 PM
Convert String with sql Joe Spenceley Access Newsgroup 2 09-09-2004 02:13 AM
Re: convert number to string Lynn Trapp Access Newsgroup 0 08-18-2004 04:15 PM
Re: convert number to string Brendan Reynolds Access Newsgroup 0 08-18-2004 04:14 PM



All times are GMT. The time now is 08:22 PM.
Microsoft Office Forums is not affiliated with Microsoft Corporation.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92