473,473 Members | 1,857 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Strip Time of a Date?

7 New Member
Hello! I'm looking for help on how to strip time data of my date string. The information in each field is extracted from another type database into access.
For example:

12/31/2007 12:34:56:789
2/2/2007 00:00:00

I would want to be
12/31/2007
2/2/2007

Another problem is that the dates are different sizes ranging from 8-10 Characters long. I've tried using left/right/len and replace functions. As well as Sql statements to adjust the format from text to DATETIME. When I try not all the fields switch over.

Been working on this problem for awhile. I was able to make a macro in Excel to accomplish this task. However I want to be able to do this in ACCESS for automation purposes. Thank you for the help!

Using ACCESS 2000-2003. Various computers.
Apr 22 '07 #1
15 22192
Corster
36 New Member
Have you tried just formatting as a date?

Expand|Select|Wrap|Line Numbers
  1. Format(YourVariableOrObjectValue, "dd/mm/yyyy")
Apr 23 '07 #2
justinf
7 New Member
Have you tried just formatting as a date?
I have tried using Format in a query. As well as using Alter table/Column lines in ACCESS SQL. When I try those, some records get erased. namely those that are like e.g.

2/2/2007 12:34:56:789

I am thinking access doesn't recognize the time format. I am not for sure. I'm dealing with around 12k plus records, and unfortunately the Dates in each of the fields are important for further database functionality down the road. I appreciate the feedback, and i'll be still working on it. Thank you!
Apr 23 '07 #3
pks00
280 Recognized Expert Contributor
use DateValue

so DateValue(mydatevariable) returns the date portion of a date/time value
Apr 23 '07 #4
justinf
7 New Member
use DateValue

so DateValue(mydatevariable) returns the date portion of a date/time value
I will give it a shot. Will report what happens. Thank you!
Apr 23 '07 #5
justinf
7 New Member
I will give it a shot. Will report what happens. Thank you!
I tried it out. It does work for some of the values. However some values still get erased. Still working on it. I used it in a query format:

datevalue([start_dt])

Thank you for the help!
Apr 23 '07 #6
justinf
7 New Member
Trying a different route...
Ok. I'm going to try a different route. So far so good. Just need to try it at work now. Instead of trying to find and replace data in Access, i'm going to use Excel from Access. I've been piecing together ideas from various resources. Finally found something that works... well at home anyways.. Code to follow.

Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Sub GetExcel()
  3. Dim xlApp As Excel.Application
  4. Set xlApp = Excel.Application
  5. xlApp.Visible = True
  6. Workbooks.Open Filename:="filename"
  7.     Cells.Replace "??:??:??:*", " "
  8.     Cells.Replace "??:??:??", " "
  9.     xlApp.SaveWorkspace
  10.  
  11.     End Sub
  12.  
Hopefully I have everything right. At least it seems to work. Appreciate any and all input. And of course. Thank you for the help!
Apr 24 '07 #7
NeoPa
32,556 Recognized Expert Moderator MVP
Are you sure the time part comes as "??:??:??:???" rather than "??:??:??.???"?
The former doesn't make sense as the last three digits should be fractions of a second and not a separate subfield. If your data is formatted as the former then that is why you'll have problems with it.
Apr 25 '07 #8
justinf
7 New Member
Are you sure the time part comes as "??:??:??:???" rather than "??:??:??.???"?
The former doesn't make sense as the last three digits should be fractions of a second and not a separate subfield. If your data is formatted as the former then that is why you'll have problems with it.
Unfortunately that is the way the data comes out from another database. "??:??:??:???" I have no control over that. I simply export the data, then do the other tasks with it. However, when using the code above, it replaces the time data with a blank with makes the date information more usable for my purposes. Seems to work at work so far! I'm still new to using code for just about anything. Alot of experimenting going on. Appreciate the input, and the explanation of why i've been having so many problems for the past (several) months. Thank you!
Apr 25 '07 #9
NeoPa
32,556 Recognized Expert Moderator MVP
No problem.
One technique I often use when data supplied to me from an external source wants to play silly-buggers, is to import it first into a temporary table whose design is very forgiving of any data found in the import.
From there I use an append query to load that data (fiddled where necessary) into the table I need the data in. This gives me a lot of power over how to handle data that's not already formatted how I would like it - converting strings to date/times; numerics etc where required.
Apr 26 '07 #10
Corster
36 New Member
How about stripping the last 4 numbers off?
Expand|Select|Wrap|Line Numbers
  1. Mid(CStr(YourDate), 1, Len(CStr(YourDate)-4))
Might work.
Apr 26 '07 #11
pks00
280 Recognized Expert Contributor
Hi JustinF, Sorry for the late reply. Im only a part-timer on thescripts so I dont always reply on time.

Now has this been sorted?

If u get any crap on the end of the date, Im thinking a vba function here to use in your query
eg

select ClearCrapOutMeDate(mydatevariable) as CleanDate
from mytable


and a function defined as

Expand|Select|Wrap|Line Numbers
  1. public function ClearCrapOutMeDate(sDate as String)
  2.     Dim sLine() as String
  3.  
  4.     ClearCrapOutMeDate = sDate
  5.  
  6.     if Instr(1, sDate, " ") > 0 then
  7.         sLine = Split(sDate," ")
  8.         ClearCrapOutMeDate = sLine(0)
  9.     end if
  10. end function
  11.  
Apr 27 '07 #12
NeoPa
32,556 Recognized Expert Moderator MVP
You might want :
Expand|Select|Wrap|Line Numbers
  1. Public Function ClearCrapOutMeDate(sDate As String) As Date
as the first line though. A small change.
Apr 27 '07 #13
pks00
280 Recognized Expert Contributor
You might want :
Expand|Select|Wrap|Line Numbers
  1. Public Function ClearCrapOutMeDate(sDate As String) As Date
as the first line though. A small change.
I left it as variant just in case invalid string is passed i.e. something that isnt a date or doesnt have a space.
Apr 28 '07 #14
NeoPa
32,556 Recognized Expert Moderator MVP
Oh OK. Fair point.
I suppose the OP can choose which version suits their situation best ;)
Apr 30 '07 #15
justinf
7 New Member
I appreciate all the ideas. When I get a chance i'll play with those ideas to see if they work. So far so good with tapping into excel at the moment. I'm very far from being proficient however getting better everyday! I really appreciate the help! Thank you all!
May 1 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: jason | last post by:
Could someone help me work out out a way to either convert a smalldatetime value from my database(access) to a normal date with out the trailing time. Is it simple matter of using FormatDate or...
16
by: PK9 | last post by:
I have a string variable that holds the equivalent of a DateTime value. I pulled this datetime from the database and I want to strip off the time portion before displaying to the user. I am...
9
by: scott | last post by:
I have a field with datetime values like below LISTING 1. Can someone help me write code strip the time part so only values like "7/15/2005" will be left. Note - We must be able to strip dates...
3
by: Michael Evanchik | last post by:
I was coding along in asp.net (which i must say is great) But using the tab control that microsoft made, when i click on other tabs and go to print(native internet explorer print) it does not print...
3
by: Michal A. Valasek | last post by:
Hello, I want to transform text with HTML markup to plain text. Is there some simple way how to do it? I can surely write my own function, which would simply strip everything with < and >....
6
by: aiwarrior | last post by:
Hi Im writing a personal wrapper to the perl script offered by rapidshare, so that im able to use multiple files and glob pathnames, but im using a file so i can track and resume any uploading...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.