Solved

# Character Date

Posted on 2006-11-15
Medium Priority
313 Views
What is the formula for converting a date format of 1/1/2007 to either a serial date for character data such as 20070101?

Thanks again...
0
Question by:jfringer
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 65

Accepted Solution

ID: 17949077
format("mydate","YYYYMMDD")

0

LVL 61

Expert Comment

ID: 17949079
Format(YourDate,"yyyymmdd")
0

LVL 65

Expert Comment

ID: 17949088
in fact u can use a variety of different masks within the format command

DD-MMM-YYYY   will produce 01-JAN-2006
MM/DD/YY will produce 01/01/06

all sorts of fun

0

LVL 2

Expert Comment

ID: 17949104
There is a builtin serial function:

DateSerial (Â«yearÂ», Â«monthÂ», Â«dayÂ»)

This will return the serial value for that day...  Not sure if that's what you were looking for or not....
0

LVL 65

Expert Comment

ID: 17949184
DateSerial returns a date, not a serial value
0

LVL 120

Expert Comment

ID: 17949410
to convert a date to serial
place this functions in a module

Function Date2Serial(varDate As Date)
Dim yYear As Integer
yYear = Right(varDate, 4)

If IsLeapYear(yYear) = True Then
Date2Serial = varDate - CDate("January 1,1900") + 2
Else
Date2Serial = varDate - CDate("January 1,1900") + 1
End If
End Function

Public Function IsLeapYear(varYear As Integer) As Boolean
IsLeapYear = (Day(DateSerial(varYear, 3, 0)) = 29)
End Function

0

LVL 11

Expert Comment

ID: 17949554
year(mydate) & right("00" & month(mydate), 2) & right("00" & day(mydate), 2)

just for fun and an alternative way of breaking out the individual pieces

;)
0

LVL 26

Expert Comment

ID: 17949576
(just for sh!ts and giggles)

You could use your date as a seed for a random number:

myNumber = yourdatefield *RND()

:-)

0

LVL 58

Expert Comment

ID: 17952726
> DateSerial returns a date, not a serial value

There is no real difference. DateSerial() returns a serial value, with side instructions to display it using default date format. It's still what the name implies, a serial. cf:

Format( Now(), "0.0")
CDbl(Now())
Int( Now() )
Format( 2^16, "ddddd" )
Format( #1:43 PM#, "percent" )

jfringer,

You have ample answers about "character dates". For "serial dates", as you see, there is no conversion needed as such, because all dates are serial dates. However, to remove the default date formatting, you can change the format of the date field to "0", use the dummy CDbl() conversion, or true conversions like Int(), CLng(), or -- again -- Format().

Reversly, you can create a Long Integer field and format it as date (I do that often).

(Â°vÂ°)
0

LVL 65

Expert Comment

ID: 17956405
Harfang, for sure, ok, default format is date, so apologies mdegood
If u want the long value, u will have to specify the exact data type if u want to assign it to a variable
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preparing an email is something we should all take special care with â€“ especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challenâ€¦
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
If youâ€™ve ever visited a web page and noticed a cool font that you really liked the look of, but couldnâ€™t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yoâ€¦
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a qâ€¦
###### Suggested Courses
Course of the Month10 days, 21 hours left to enroll