Solved

Character Date

Posted on 2006-11-15
10
265 Views
Last Modified: 2013-12-03
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
Comment
Question by:jfringer
10 Comments
 
LVL 65

Accepted Solution

by:
rockiroads earned 250 total points
ID: 17949077
format("mydate","YYYYMMDD")

0
 
LVL 61

Expert Comment

by:mbizup
ID: 17949079
Format(YourDate,"yyyymmdd")
0
 
LVL 65

Expert Comment

by:rockiroads
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

hilite Format and hit F1 for more info
0
 
LVL 2

Expert Comment

by:mdegood
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

by:rockiroads
ID: 17949184
DateSerial returns a date, not a serial value
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
LVL 119

Expert Comment

by:Rey Obrero
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

by:fanopoe
ID: 17949554
don't forget about:
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

by:dannywareham
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

by:harfang
ID: 17952726
rockiroads:
> 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

by:rockiroads
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now