2 Replies - 2209 Views - Last Post: 18 March 2013 - 06:33 AM Rate Topic: -----

#1 thanzeem7  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 14-January 13

Remove String from a variable value.

Posted 18 March 2013 - 06:12 AM

In my database i have data with datetime type. I read this data from database and convert to string and stored in a string variable. I want to remove time part from the value. How i do this??
Is This A Good Question/Topic? 0
  • +

Replies To: Remove String from a variable value.

#2 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3721
  • View blog
  • Posts: 12,957
  • Joined: 12-December 12

Re: Remove String from a variable value.

Posted 18 March 2013 - 06:27 AM

In the SQL statement I believe you can do this (for MSSQL):

CAST(YourField AS DATE)

although I haven't tested it.

If you wish to do this after you have created the string version then advise us of the current format of this string; if it is of a fixed length then you might use Substring() to grab the part that you need.
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1606
  • View blog
  • Posts: 5,163
  • Joined: 25-September 09

Re: Remove String from a variable value.

Posted 18 March 2013 - 06:33 AM

You can also use the .ToString("MM/dd/yyyy") but you would have to cast to date first.

For example:
myDateOnlyString = CDate(myReader("AccessDate")).ToString("MM/dd/yyyy")


So if the value came from the database as 03/18/2013 09:32:00 AM

myDateOnlyString would be "03/18/2013"

This post has been edited by CharlieMay: 18 March 2013 - 06:33 AM

Was This Post Helpful? 1
  • +
  • -

Page 1 of 1