amillyard
asked on
datetime string conversion
I am trying to get the nowGMT into a string ! ... but the following script is not working out for me yet.
what am I doing wrong?
your time and efforts with this enquiry are much apprieated.
what am I doing wrong?
your time and efforts with this enquiry are much apprieated.
DateTime now = DateTime.Now;
DateTime nowGMT = now.ToUniversalTime();
string nowGMTstring = nowGMT.ToString();
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Babycorn-Starfish:
Yes, I agree, no apparent difference -- except the 'Time' text removed.
DateTime now = DateTime.Now();
Date nowGMT = now.ToUniversalTime(); --- nowGMT is setup here and gets the current date/time data
"nowGMT" has all the data I that is required ... just need to convert that to a string format -- so I can make is part of a sql statement (string formatted).
string nowGMTstring = nowGMT.ToString(); -- this was my attempt to convert to string.
Yes, I agree, no apparent difference -- except the 'Time' text removed.
DateTime now = DateTime.Now();
Date nowGMT = now.ToUniversalTime(); --- nowGMT is setup here and gets the current date/time data
"nowGMT" has all the data I that is required ... just need to convert that to a string format -- so I can make is part of a sql statement (string formatted).
string nowGMTstring = nowGMT.ToString(); -- this was my attempt to convert to string.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
nothing is being updated when posting the database update -- when I take out the nowGMT column -- db updates ok.
[DateTimeStamp] on the db is setup as a 'smalldatetime' in structure.
[DateTimeStamp] on the db is setup as a 'smalldatetime' in structure.
DateTime now = DateTime.Now;
DateTime nowGMT = now.ToUniversalTime();
string nowGMTstring = nowGMT.ToString();
string sql = "UPDATE [MasterAccounts] set [TelemarketingInUseLock]=" + StatusUpdate + "[DateTimeStamp]=" + nowGMT + " WHERE [MasterAccount_ID]=" + (String)Session["MasterAccount"];
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Babycorn-Starfish:
yes, it is actual code, I was trying with "nowGMT" and with "nowGMTstring" -- to see if there was any different (i.e. perhaps I did not have to convert to string).
asvforce:
have tried the code update as indicated -- db still refuing to update itself.
if I take out the "", [DateTimeStamp]='" + nowGMT +" for example -- db updates fine.
yes, it is actual code, I was trying with "nowGMT" and with "nowGMTstring" -- to see if there was any different (i.e. perhaps I did not have to convert to string).
asvforce:
have tried the code update as indicated -- db still refuing to update itself.
if I take out the "", [DateTimeStamp]='" + nowGMT +" for example -- db updates fine.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
same issue -- even with literal as follows -- this is prevent a db update
string sql = "UPDATE [MasterAccounts] set [TelemarketingInUseLock]=" + StatusUpdate + "[DateTimeStamp]='19/11/2007 12:24:00' WHERE [MasterAccount_ID]=" + (String)Session["MasterAccount"];
ASKER
submitting this sql string -- works fine (but obviously no date/time updating going on)
string sql = "UPDATE [MasterAccounts] set [TelemarketingInUseLock]=" + StatusUpdate + " WHERE [MasterAccount_ID]=" + (String)Session["MasterAccount"];
ASKER
in a different table, I can update the date and time ok, (when creating a new record) as follows via stored procedure: (but obviously no other string conversion / manipulation here)
DateTime now = DateTime.Now;
DateTime nowGMT = now.ToUniversalTime();
scCommand.Parameters.AddWithValue("@DateTimeStamp", nowGMT);
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
not working for me yet ... have restructured the scripting as follows:
webservice file:
public class datetimeserver : System.Web.Services.WebSer vice
{
[WebMethod]
public DateTime GetServerTime()
{
return DateTime.Now;
}
}
.cs file
datetimeserver service = new datetimeserver();
DateTime serverTime = service.GetServerTime();
string sql = "UPDATE [MasterAccounts] set [RecordInUseLock]='" + StatusUpdate + "', [DateTimeStamp]='" + serverTime.ToString() + "' WHERE [MasterAccount_ID]=" + (String)Session["MasterAcc ount"];
cannot get this part to work yet -- ", [DateTimeStamp]='" + serverTime.ToString()
datetimestamp is a smalldatetime variable
webservice file:
public class datetimeserver : System.Web.Services.WebSer
{
[WebMethod]
public DateTime GetServerTime()
{
return DateTime.Now;
}
}
.cs file
datetimeserver service = new datetimeserver();
DateTime serverTime = service.GetServerTime();
string sql = "UPDATE [MasterAccounts] set [RecordInUseLock]='" + StatusUpdate + "', [DateTimeStamp]='" + serverTime.ToString() + "' WHERE [MasterAccount_ID]=" + (String)Session["MasterAcc
cannot get this part to work yet -- ", [DateTimeStamp]='" + serverTime.ToString()
datetimestamp is a smalldatetime variable
ASKER
fyi -- I managed to the string version working -- had to change the datetimestamp to a string variable though.
problem is that I am getting to output results for the time part as follows:
3:22:40 AM - when running scripts via the server
08:19:20 - locally (development platform) ran
what I would to achieve though is:
xx/xx/xxxx xx:xx:xx
day/month/year hour/min/secs
what I also would like to achieve is obviously for this to be updating as a smalldatetime variable in db table.
problem is that I am getting to output results for the time part as follows:
3:22:40 AM - when running scripts via the server
08:19:20 - locally (development platform) ran
what I would to achieve though is:
xx/xx/xxxx xx:xx:xx
day/month/year hour/min/secs
what I also would like to achieve is obviously for this to be updating as a smalldatetime variable in db table.
ASKER
Resolved this in the end using the following to correct the formatting issue:
string serverDateTime = serverTime.ToString("MMM dd, yyyy HH:mm:ss");
string serverDateTime = serverTime.ToString("MMM dd, yyyy HH:mm:ss");
ASKER
cannot do that change, as 'Date' is then not visible in the namespace.