473,396 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Strip Time from Datetime

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 with double digit months and days, so
i can't just use the right function with a hard coded parameter.
LISTING 1

mydatetimevalue = "7/15/2005 8:00:00 AM"
Jul 22 '05 #1
9 18033
0 = vbGeneralDate
1 = vbLongDate
2 = vbShortDate
3 = vbLongTime
4 = vbShortTime

Response.Write FormatDateTime(mydatetimevalue, 2)

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"scott" <sb*****@mileslumber.com> wrote in message
news:eN**************@TK2MSFTNGP14.phx.gbl...
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 with double digit months and days, so i can't just use the right function with a hard coded parameter.
LISTING 1

mydatetimevalue = "7/15/2005 8:00:00 AM"

Jul 22 '05 #2
scott wrote:
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 with double digit months and
days, so i can't just use the right function with a hard coded
parameter.

LISTING 1

mydatetimevalue = "7/15/2005 8:00:00 AM"


Use the FormatDateTime function. See:
http://www.aspfaq.com/show.asp?id=2313

Or are you are asking how to do it in a query? If so, you need to tell us
what database you are using.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #3
i've got to actually strip the time off, not just display because the date
is a parameter for a sql sproc.
"Steven Burn" <so*******@in-time.invalid> wrote in message
news:%2******************@TK2MSFTNGP15.phx.gbl...
0 = vbGeneralDate
1 = vbLongDate
2 = vbShortDate
3 = vbLongTime
4 = vbShortTime

Response.Write FormatDateTime(mydatetimevalue, 2)

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!

"scott" <sb*****@mileslumber.com> wrote in message
news:eN**************@TK2MSFTNGP14.phx.gbl...
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 with double digit months and days,

so
i can't just use the right function with a hard coded parameter.
LISTING 1

mydatetimevalue = "7/15/2005 8:00:00 AM"


Jul 22 '05 #4
I need just need some nifty use of string functions to chop off the time and
leave m/d/yyyy string. it's going to a sproc as a parameter so time needs to
be choped off, not just displayed right.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:O1**************@TK2MSFTNGP12.phx.gbl...
scott wrote:
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 with double digit months and
days, so i can't just use the right function with a hard coded
parameter.

LISTING 1

mydatetimevalue = "7/15/2005 8:00:00 AM"


Use the FormatDateTime function. See:
http://www.aspfaq.com/show.asp?id=2313

Or are you are asking how to do it in a query? If so, you need to tell us
what database you are using.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 22 '05 #5
"scott" <sb*****@mileslumber.com> wrote in message
news:eN**************@TK2MSFTNGP14.phx.gbl...
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 with double digit months and days, so i can't just use the right function with a hard coded parameter.
LISTING 1

mydatetimevalue = "7/15/2005 8:00:00 AM"

WScript.Echo Split(mydatetimevalue," ")(0)
Jul 22 '05 #6
Then you'll want to read this:
http://www.aspfaq.com/show.asp?id=2040

What datatype is the parameter?

Bob Barrows

scott wrote:
I need just need some nifty use of string functions to chop off the
time and leave m/d/yyyy string. it's going to a sproc as a parameter
so time needs to be choped off, not just displayed right.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:O1**************@TK2MSFTNGP12.phx.gbl...
scott wrote:
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 with double digit months and
days, so i can't just use the right function with a hard coded
parameter.

LISTING 1

mydatetimevalue = "7/15/2005 8:00:00 AM"


Use the FormatDateTime function. See:
http://www.aspfaq.com/show.asp?id=2313

Or are you are asking how to do it in a query? If so, you need to
tell us what database you are using.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so
I don't check it very often. If you must reply off-line, then remove
the "NO SPAM"


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #7
it's datetime. Below is my sproc that works fine with m/d/yyyy datebase
values. now, if i add the time to the m/d/yyyy value in my database, my
sproc won't recognize them.

SPROC LISTING

CREATE PROCEDURE mlc_CALENDAR_GetDayEvents
/*
Returns calendar events for a single day on team calendar

*/
(
@dtDate datetime
)
AS
BEGIN

SELECT *
FROM t_events
WHERE eventArchived = 0 AND
eventStart_date >= CONVERT(datetime,(convert(varchar,@dtDate,101) + ' 12:00
AM')) AND
eventEnd_date <= CONVERT(datetime,(convert(varchar,@dtDate,101) + ' 11:59
PM'))
END
GO

"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:Or**************@TK2MSFTNGP14.phx.gbl...
Then you'll want to read this:
http://www.aspfaq.com/show.asp?id=2040

What datatype is the parameter?

Bob Barrows

scott wrote:
I need just need some nifty use of string functions to chop off the
time and leave m/d/yyyy string. it's going to a sproc as a parameter
so time needs to be choped off, not just displayed right.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:O1**************@TK2MSFTNGP12.phx.gbl...
scott wrote:
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 with double digit months and
days, so i can't just use the right function with a hard coded
parameter.

LISTING 1

mydatetimevalue = "7/15/2005 8:00:00 AM"

Use the FormatDateTime function. See:
http://www.aspfaq.com/show.asp?id=2313

Or are you are asking how to do it in a query? If so, you need to
tell us what database you are using.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so
I don't check it very often. If you must reply off-line, then remove
the "NO SPAM"


--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 22 '05 #8
"McKirahan" wrote in message news:TZ********************@comcast.com...
: "scott" <sb*****@mileslumber.com> wrote in message
: news:eN**************@TK2MSFTNGP14.phx.gbl...
: > 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 with double digit months and days,
: so
: > i can't just use the right function with a hard coded parameter.
: >
: >
: > LISTING 1
: >
: > mydatetimevalue = "7/15/2005 8:00:00 AM"
:
:
: WScript.Echo Split(mydatetimevalue," ")(0)

You beat me too it but you don't need " " do ya'? Space is the default
delimiter.

WScript.Echo Split(mydatetimevalue)(0)

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp
Jul 22 '05 #9
> it's datetime. Below is my sproc that works fine with m/d/yyyy

Yes, but it MIGHT NOT TOMORROW! Use a *SAFE* format, please. YYYYMMDD
works for SQL Server,YYYY-MM-DD works for Access. Please read
http://www.aspfaq.com/2023 -- just because something works fine does not
make it the right thing to do.
now, if i add the time to the m/d/yyyy value in my database, my sproc
won't recognize them.
What do you mean? Do you get an error message? If so, what is it?
SELECT *
FROM t_events
WHERE eventArchived = 0 AND
eventStart_date >= CONVERT(datetime,(convert(varchar,@dtDate,101) + '
12:00 AM')) AND
eventEnd_date <= CONVERT(datetime,(convert(varchar,@dtDate,101) + ' 11:59
PM'))


Do not use SELECT * in production code. And try the following instead, if
you look atthe queyr plan I think you will find that it is at least as
efficient if not more so, and is much easier to read.

-- always name the owner!
CREATE PROCEDURE dbo.mlc_CALENDAR_GetDayEvents
@dt SMALLDATETIME
AS
BEGIN
SET NOCOUNT ON

-- most efficient way to strip time:
SET @dt = DATEADD(DAY, 0, DATEDIFF(DAY, 0, @dt))

SELECT Column_Names
FROM t_events
WHERE eventArchived = 0
AND eventStart_date >= @dt
AND eventEnd_date < (@dt+1)
-- use less then the next day at midnight
-- then you don't lose values like 11:59:30
END
GO

Now, do you really mean to only capture events that last < 24 hours? Or did
you mean to capture events that start on @dt, end on @dt, or are in progress
on @dt?

A
Jul 22 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...

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.